Clustering Lab (code by Claude, guidance by Georgios Evangelidis)

Silhouette plot: one horizontal bar per point, grouped by cluster and sorted. Dashed line = mean silhouette. Bars below 0 suggest the point sits closer to another cluster.

K-means

Hierarchical

DBSCAN

Evaluation

What do these metrics mean?

Internal metrics use only the data and the labels:

  • Silhouette s(i) = (b − a) / max(a, b), where a is the mean distance to the point's own cluster and b the mean distance to the nearest other cluster. Range −1…1, higher is better.
  • Davies–Bouldin: average over clusters of the worst ratio (scatterᵢ + scatterⱼ) / distance(centroidᵢ, centroidⱼ). ≥ 0, lower is better.
  • Calinski–Harabasz: (between-cluster dispersion / (k − 1)) ÷ (within-cluster dispersion / (n − k)). Higher is better.
  • SSE / inertia: Σ squared distances to cluster centroids. Always falls as k rises, so it can't choose k by itself (use the elbow).

External metrics compare with the ground-truth labels (only for generated data):

  • Adjusted Rand Index: pairwise agreement corrected for chance. 1 = identical, ≈ 0 = random.
  • Normalised Mutual Information: shared information between the two partitions, 0…1 (arithmetic normalisation).
  • Purity: fraction of points in the majority true class of their cluster. Biased upwards by many small clusters.

DBSCAN noise points are left out of internal metrics; for external metrics, noise counts as one extra group.