Foundations to Frontier
Tests
D. Classical Machine Learning › D0 Core Concepts (concept pages)

Clustering Evaluation: Silhouette, Davies–Bouldin, Calinski–Harabasz, ARI and NMI

Without labels, how do you know whether a clustering is good, or how many clusters there are? Internal indices score a clustering from the data alone: the silhouette compares each point's distance to its own cluster with its distance to the nearest other cluster, Davies–Bouldin averages the worst ratio of spread to separation, and Calinski–Harabasz compares between-cluster with within-cluster dispersion. When true groups are known, external indices compare with them: the adjusted Rand index and normalised mutual information. This page defines the indices, their biases (most favour compact, round clusters), and how to use them to choose k responsibly. In the exercises you implement all five indices and k-means; then you test whether the internal indices recover the true number of clusters on four datasets and whether they agree with the truth when clusters are not round.

Level 0: Foundation

★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.

Grading groups with no answer key

Sort a pile of buttons into groups. A teacher with an answer key can grade you directly (external scores). Without one, you can still ask whether buttons in the same group look alike and different groups look different (internal scores). But “looks alike” depends on what you measure. Two crescent-shaped groups might be graded worse than a sloppy split into two blobs.

How good is this clustering?
data:
silhouette 0.686 (higher better; best k = 4)
Davies–Bouldin 0.410 (lower better; best k = 4)
Calinski–Harabasz 523 (higher better; best k = 4)
ARI against the true groups 1.000 (true k = 4)
On round blobs all indices agree with the truth. On elongated groups or moons, the internal indices reward round, compact clusters, so they prefer the wrong k or the wrong shape: internal scores measure what k-means optimises, not whether the groups are meaningful.
Why engineers care

Clustering flight regimes, operating modes or fault signatures in telemetry is usually done without labels. Choosing the number of clusters from an index without checking what the clusters mean can produce tidy-looking groups that correspond to nothing physical.

📝 Quick check (Level 0)
0/3 answered
  1. 1. An internal clustering score uses…
  2. 2. An external score compares clusters with…
  3. 3. In the demo, internal scores on the moons…

Level 1: Beginner

★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.

The indices

Index Type Range Better Idea
silhouette internal −1 to 1 higher (b − a)/max(a, b) per point
Davies–Bouldin internal ≥ 0 lower average of the worst (spread_i + spread_j)/distance_ij
Calinski–Harabasz internal ≥ 0 higher between / within dispersion, scaled
adjusted Rand index (ARI) external about −0.5 to 1 higher pair agreement corrected for chance (0 = random)
normalised mutual information (NMI) external 0 to 1 higher shared information between labelings

Other tools for choosing k: the elbow of the inertia curve, the gap statistic, information criteria (BIC for Gaussian mixtures), and stability (do clusters persist under resampling?).

from sklearn.metrics import silhouette_score, davies_bouldin_score, calinski_harabasz_score, adjusted_rand_score, normalized_mutual_info_score
for k in range(2, 9):
    lab = KMeans(k, n_init=10).fit_predict(X)
    print(k, silhouette_score(X, lab), davies_bouldin_score(X, lab), calinski_harabasz_score(X, lab))
📝 Quick check (Level 1)
0/3 answered
  1. 1. A silhouette near 1 means…
  2. 2. For Davies–Bouldin, better is…
  3. 3. ARI of a random labelling is about…

Level 2: Intermediate

★★★☆☆ Intermediate⏱ 35 minUndergraduate students and practising engineers.

Definitions

  • Silhouette of point i: a = mean distance to the other points in its cluster, b = smallest mean distance to another cluster, s = (b − a)/max(a, b). Average over points.
  • Davies–Bouldin: with sᵢ the mean distance of cluster i’s points to its centroid and dᵢⱼ the distance between centroids, DB = mean over i of maxⱼ (sᵢ + sⱼ)/dᵢⱼ.
  • Calinski–Harabasz: [tr B/(k − 1)] / [tr W/(n − k)], where B and W are between- and within-cluster scatter.
  • ARI: the Rand index (fraction of point pairs on which two labelings agree), corrected so that its expectation under random labelings with the same cluster sizes is 0.
  • NMI: I(U; V) divided by the mean of H(U) and H(V). It is invariant to renaming clusters.

All three internal indices rely on distances to centres or within clusters, so they favour convex, similarly sized, well-separated clusters, which is exactly what k-means produces.

🐍 Exercise 1: clustering indices from scratch
Implement the silhouette, Davies–Bouldin and Calinski–Harabasz indices, the contingency table, the adjusted Rand index and normalised mutual information, and k-means with several restarts; verify them on hand-computable examples and check that ARI of random labelings is about 0.
📝 Quick check (Level 2)
0/3 answered
  1. 1. Renaming cluster labels changes ARI and NMI by…
  2. 2. Internal indices tend to favour…
  3. 3. Calinski–Harabasz compares…

Level 3: Advanced

★★★★☆ Advanced⏱ 30 minGraduate level, with full derivations and proofs.

Evaluating clusterings responsibly

  • Match the index to the algorithm’s assumptions. For density or connectivity clusters (DBSCAN, single linkage, D8), use density-based validity indices or inspect directly; centroid indices will mislead.
  • Choose k with several signals: indices, stability under bootstrap, interpretability, and downstream usefulness.
  • External labels, when available for a subset, are the best check. Report ARI or NMI.
  • Scale features first (D0.12): distance-based indices depend on units.
  • Large n: the silhouette is O(n²); sample, or use the simplified centroid silhouette.

Interview questions.

  • How do you choose k for k-means? Elbow, silhouette, gap statistic, stability and domain sense; no index is definitive.
  • Can a clustering with a lower silhouette be better? Yes, if the true groups are not round, as with the moons.
📝 Quick check (Level 3)
0/3 answered
  1. 1. For DBSCAN results on curved clusters, silhouette is…
  2. 2. Stability-based selection of k checks…
  3. 3. Silhouette cost for n points is…

Level 4: Expert

★★★★★ Expert⏱ 30 minResearchers: original papers and open problems.

Do internal indices find the truth?

Exercise 1. For two well-separated pairs of points:

  • the silhouette is (b − a)/b with a = 1;
  • Davies–Bouldin is 0.1;
  • Calinski–Harabasz is 200.

Relabelled clusterings get ARI = NMI = 1, and random labelings average ARI ≈ 0. On three separated blobs, k-means scores silhouette 0.822, DB 0.249 and ARI 1.000.

Exercise 2a: choosing k from 2 to 8 with k-means (300 points per dataset).

Dataset (true k) Silhouette picks DB picks CH picks ARI at the true k
4 round blobs (4) 4 4 4 0.99
3 blobs, unequal spread (3) 2 3 3 0.81
3 elongated blobs (3) 8 8 8 0.26
2 moons (2) 8 8 8 0.27

Exercise 2b: moons, k = 2.

Clustering Silhouette Davies–Bouldin ARI
k-means 0.49 0.79 0.20
single linkage 0.33 1.17 1.00
  • When clusters are round and separated, all three indices recover k.
  • With unequal spreads, the silhouette merges the two closer blobs.
  • With elongated or curved groups, every index prefers many small round pieces (k = 8). Even at the true k, k-means splits the groups across their long axis (ARI ≈ 0.26).
  • Most strikingly, on the moons the internal indices rate the wrong clustering clearly better than the perfect one. They measure compactness, not correctness.
🐍 Exercise 2 (research): do internal indices find the true clusters?
On round, unequally spread, elongated and moon-shaped data, run k-means for k = 2…8 and record the k chosen by the silhouette, Davies–Bouldin and Calinski–Harabasz indices and the ARI at the true k; then compare k-means and single-linkage clusterings of the moons by internal indices and by ARI.

Clustering evaluation in AI, robotics and aerospace

  • Flight-regime discovery: check clusters against known phases (take-off, cruise, landing) as an external sanity check.
  • Fault signature clustering: stability across time windows matters more than a single index.
  • Terrain classification from rover sensors: labelled patches give ARI on a subset.
  • Embedding analysis: NMI between clusters of learned features and known classes.

References

  1. P. J. Rousseeuw (1987). “Silhouettes: a graphical aid to the interpretation and validation of cluster analysis.” J. Comput. Appl. Math. 20.
  2. D. L. Davies, D. W. Bouldin (1979). “A cluster separation measure.” IEEE TPAMI 1(2).
  3. T. Caliński, J. Harabasz (1974). “A dendrite method for cluster analysis.” Communications in Statistics 3(1).
  4. L. Hubert, P. Arabie (1985). “Comparing partitions.” Journal of Classification 2.
  5. R. Tibshirani, G. Walther, T. Hastie (2001). “Estimating the number of clusters in a data set via the gap statistic.” JRSS B 63(2).