MoonSay /Tutorials/Machine Learning Interview #3
Contents
  1. 01Introduction
  2. 02What clustering is
  3. 03K-means
  4. 04Choosing K, and where K-means fails
  5. 05Gaussian mixture models and the EM algorithm
  6. 06Dirichlet process mixtures
  7. 07DBSCAN
  8. 08Hierarchical clustering
  9. 09Spectral clustering
  10. 10Putting it all together
  11. 11Interview questions and model answers
  12. 12Summary
  13. References
Clustering Algorithms/Chapter 10 of 12

10Putting it all together

10.1Same data, five definitions of a cluster

Figure 9 runs the five methods on three standardized data sets, as in the video. On well-separated round blobs every method is perfect. On elongated clusters the Gaussian mixture is perfect (1.00), spectral clustering good (0.91), DBSCAN finds the three clusters but calls 45 points noise (0.76), and K-means (0.51) and Ward (0.47), with their preference for round clusters, cut across. On the noisy moons DBSCAN is best (0.94), finding the moons and marking 9 points as noise, though it also makes a tiny third cluster; Ward (0.64), the Gaussian mixture (0.50), K-means (0.45) and spectral clustering with this graph (0.36) fail. No method wins everywhere: each wins where its definition of a cluster matches the data.

Five methods on three standardized data sets. Numbers: adjusted Rand index against the generating groups (the 14 scattered points of the last row are excluded); crosses: DBSCAN noise. Parameters as in the video: K-means, mixture, spectral (10 neighbours) and Ward with the true number of clusters; DBSCAN with minPts =6 and \varepsilon=0.3, 0.18, 0.22. Data: computed for this tutorial with scikit-learn, with the same data and parameters as the companion video, after the comparison in the scikit-learn documentation (Pedregosa et al., 2011).
Figure 9. Five methods on three standardized data sets. Numbers: adjusted Rand index against the generating groups (the 14 scattered points of the last row are excluded); crosses: DBSCAN noise. Parameters as in the video: K-means, mixture, spectral (10 neighbours) and Ward with the true number of clusters; DBSCAN with minPts =6 and \varepsilon=0.3, 0.18, 0.22. Data: computed for this tutorial with scikit-learn, with the same data and parameters as the companion video, after the comparison in the scikit-learn documentation (Pedregosa et al., 2011).
K-meansGaussian mixtureDBSCANHierarchicalSpectral
A cluster ispoints near a centrea Gaussian bloba dense regiona branch of a merge treea well-connected piece of a graph
NeedsKK (or \alpha for a DP)\varepsilon, minPtslinkage, cut heightgraph, K
Shapesround, similar sizeellipsesanydepends on linkageany connected shape
Assignmenthardsofthard, plus noisehard, nestedhard
Outlierspull the centreswiden componentslabelled noisesingle linkage chainscan bridge clusters
CostO(nKd) per iterationO(nKd^2) per iterationO(n\log n) to O(n^2)O(n^2) to O(n^3)eigenvectors, O(n^3) dense
Guaranteelocal minimum of Jlocal maximum of \ln Ldeterministic for core pointsgreedyrelaxation of a cut
Table 1. Five clustering methods compared. Sources: Sections 3–9; Hastie et al. (2009); Bishop (2006); Ester et al. (1996); von Luxburg (2007).

10.2A practical recipe

  1. Decide what “similar” means for the application, choose the features, and standardize them (or weight them deliberately).
  2. Start with K-means (k-means++, several restarts) as a fast baseline; look at the elbow and the silhouette over a range of K.
  3. Use a Gaussian mixture when clusters may be elongated or of different sizes, or when you need membership probabilities; choose K with BIC, or use a Dirichlet process prior.
  4. Use DBSCAN or HDBSCAN for irregular shapes, unknown K and outliers, especially in low-dimensional spatial data; choose \varepsilon from the k-distance graph.
  5. Use hierarchical clustering when you want structure at every scale or a picture of the relationships (dendrogram, heat map), for up to thousands of points.
  6. Use spectral clustering for connected but non-convex shapes, and check the result for different graphs.
  7. Validate: check stability across restarts, subsamples and parameters; inspect the clusters; and if some labels exist, compare with them using the adjusted Rand index.

10.3Common misconceptions

  • “K-means finds the best clustering.” It finds a local minimum of J (Theorem 1); the global problem is NP-hard (Aloise et al., 2009). Use k-means++ and restarts.
  • “K-means works for any cluster shape.” Its clusters lie in convex Voronoi cells and it prefers round clusters of similar size (Figure 3).
  • “The elbow always shows the right K.” Often there is no clear elbow (Hastie et al., 2009, Figure 14.8); the silhouette, the gap statistic and BIC can disagree, and the application may fix K anyway.
  • “Standardizing is always right.” It is a good default, but it gives noise features the same weight as informative ones, and it cannot undo correlations between features; Hastie et al. (2009, Section 14.3.3) show two well-separated groups that standardizing hides. Choosing the dissimilarity matters more than choosing the algorithm.
  • “A clustering algorithm proves that clusters exist.” Every algorithm returns clusters, even for structureless data; a dendrogram always looks like a hierarchy (Hastie et al., 2009, Section 14.3.12). The gap statistic can answer “one cluster”.
  • “A Gaussian mixture is always better than K-means.” It has many more parameters, needs more data, can degenerate, and still assumes ellipses.
  • “DBSCAN has no parameters.” It needs no K, but \varepsilon and minPts matter a great deal, and one \varepsilon cannot fit clusters of very different densities.
  • “A Dirichlet process finds the true number of clusters.” The number found depends on \alpha and on the component model; non-Gaussian clusters are split into several components.
  • “Spectral clustering does not need any choices.” The similarity graph, its scale and K are choices, and the result can change completely with them (Section 9).
  • “K-means and k-nearest neighbours are the same kind of method.” They share only the letter. K-means is unsupervised and finds K centres; k-NN is a supervised classifier or regressor that predicts from the labels of the k nearest training points, and it has no training step at all.
  • “Cluster labels mean something by themselves.” Labels are arbitrary numbers; “cluster 2” in one run may be “cluster 0” in the next. Compare clusterings with permutation-invariant scores such as the adjusted Rand index (Hubert and Arabie, 1985).