Skip to content

Clustering Metrics and Model Selection

This demo takes a few seconds to load and runs entirely in your browser (NumPy, SciPy and matplotlib via Pyodide; no tgmm or PyTorch involved).

Three Gaussian blobs, a k-means clustering with the \(K\) you choose, and every index of ClusteringMetrics recomputed live with the same formulas. Move the separation slider to watch the indices degrade as the blobs overlap, change \(K\) to see which indices are fooled, and switch on noise (uniform background points). tgmm treats noise by dropping the points labelled as noise and scaling the index by \(f=(n-n_{\text{noise}})/n\) (multiplied for higher-is-better, divided for lower-is-better indexes); the second column below does that, the first lets k-means swallow the noise into clusters.

What to look for

  • Separation: as the blobs overlap, silhouette and Calinski–Harabasz fall and Davies–Bouldin and WB rise. Dunn is the most erratic (it rests on one closest pair and one widest cluster), which is why tgmm's documentation ranks it behind the others; at low separation its best \(K\) jumps around while silhouette and CH keep pointing at \(K=3\).
  • K: at high separation almost every index peaks at the true \(K=3\); when the blobs overlap, WB-index and Davies–Bouldin (and Dunn) are the ones that wander.
  • Noise: the noise points are known here, so the second column drops them (label \(-1\)) and scales by \((n-n_{\text{noise}})/n\). Calinski–Harabasz, WB and Dunn improve a lot; silhouette and Davies–Bouldin barely move. The GMM panel cannot drop noise: it tends to spend an extra component on the background, so BIC and ICL often pick \(K=4\) or \(5\) when noise is switched on.
  • BIC vs. ICL: both are \(-2\log L+p\log n\); ICL adds \(-2\sum_i\log\max_k\tau_{ik}\), which is near 0 for well-separated components and large when they overlap. Around separation \(\approx3\) ICL already prefers fewer components than BIC, because it penalises solutions whose clusters are not clearly distinguishable (see the Model Selection tutorial).