Contents
Clustering AlgorithmsK-Means vs Gaussian Mixture vs DBSCAN vs Hierarchical
What each method means by a cluster, and the math behind it
A tutorial companion to the video Machine Learning Interview #3: K-Means vs Gaussian Mixture vs DBSCAN vs Hierarchical Clustering PDF
01Introduction
1.1The question
“How does K-means work, and how is it different from other clustering algorithms?” is a classic interview question. The first half is easy to recite: assign every point to its nearest centre, move every centre to the mean of its points, repeat. The second half is where the depth lies, because every clustering method is built on its own answer to a deeper question: what does it mean for points to belong together? Points can belong together because they are close to the same centre, because they were probably generated by the same bell-shaped blob, because they sit in the same crowded region, because they merge early in a tree of ever larger groups, or because they are strongly connected in a graph of neighbours. Each answer leads to a different algorithm, with different strengths, failure modes and parameters, and to a different picture of the same data (Figure 9).
1.2Prerequisites and notation
Prerequisites. Vectors, norms and the minimum of a quadratic function; eigenvalues and eigenvectors of a symmetric matrix; probability, Bayes’ rule, the logarithm and the normal distribution.
Notation. The data are n points x_1,\dots,x_n\in\mathbb{R}^d, with no labels. A hard clustering into K groups gives each point a label c_i\in\{1,\dots,K\}; cluster k has n_k points and mean \bar x_k. \|\cdot\| is the Euclidean norm. The K-means objective, the within-cluster sum of squares, is
where \mu_1,\dots,\mu_K are the centres. This is the convention of the video, of Arthur and Vassilvitskii (2007) (who call it the potential \phi) and of scikit-learn’s inertia_ (Pedregosa et al., 2011); some books divide by n or by 2, which changes the numbers but not the minimizer. A soft clustering gives each point a vector of membership probabilities \gamma_{i1},\dots,\gamma_{iK} that sums to one.
1.3A short history
K-means is older than its name. Steinhaus (1956) proposed dividing a body into parts that minimize the total moment of inertia; Stuart Lloyd described the alternating algorithm in 1957 for designing the quantization levels of pulse-code modulation, in a Bell Labs report that was published only in 1982 (Lloyd, 1982); MacQueen (1967) gave the method its name. Ward (1963) introduced the minimum-variance linkage for hierarchical clustering. The EM algorithm was unified by Dempster et al. (1977), which made mixture models practical. Ferguson (1973) introduced the Dirichlet process and Sethuraman (1994) its stick-breaking construction. DBSCAN (Ester et al., 1996) brought density-based clustering to large spatial databases, and spectral clustering became popular around 2000 with the normalized cut of Shi and Malik (2000) and the algorithm of Ng et al. (2002); von Luxburg (2007) wrote the standard tutorial. Seeding K-means well, a problem as old as the algorithm, was given a guarantee by Arthur and Vassilvitskii (2007). Good textbook treatments are Bishop (2006, Chapter 9) and Hastie et al. (2009, Section 14.3). Where clustering fits among the learning paradigms, and the basics of K-means, are covered in the Episode 1 tutorial.