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.
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.
- 1. An internal clustering score uses…
- 2. An external score compares clusters with…
- 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))- 1. A silhouette near 1 means…
- 2. For Davies–Bouldin, better is…
- 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.
- 1. Renaming cluster labels changes ARI and NMI by…
- 2. Internal indices tend to favour…
- 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.
- 1. For DBSCAN results on curved clusters, silhouette is…
- 2. Stability-based selection of k checks…
- 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.
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
- P. J. Rousseeuw (1987). “Silhouettes: a graphical aid to the interpretation and validation of cluster analysis.” J. Comput. Appl. Math. 20.
- D. L. Davies, D. W. Bouldin (1979). “A cluster separation measure.” IEEE TPAMI 1(2).
- T. Caliński, J. Harabasz (1974). “A dendrite method for cluster analysis.” Communications in Statistics 3(1).
- L. Hubert, P. Arabie (1985). “Comparing partitions.” Journal of Classification 2.
- R. Tibshirani, G. Walther, T. Hastie (2001). “Estimating the number of clusters in a data set via the gap statistic.” JRSS B 63(2).