Evaluating clusters: elbow, extrinsic and intrinsic measures
How to judge if a clustering is good: the elbow visual rule, intrinsic (no ground truth) and extrinsic (with labels) numerical measures and how to compute them.
Drafted with Aria, reviewed by the AiCanCode.org team · Updated . How we write and check our notes. Spotted an error? Use Give Feedback at the bottom of the page.
Why it matters
Clustering groups data points without labels. An engineer uses cluster evaluation to choose the number of clusters, to compare algorithms (k‑means, DBSCAN, GMM) and to check whether clusters match known classes (when labels exist). Good evaluation avoids over‑ or under‑splitting and supports decisions in feature engineering, anomaly detection and customer segmentation.
Key ideas
Start from first principles and simple definitions.
Cluster: a set of data points that are similar by some measure (usually Euclidean distance). I will use "point" and "vector" interchangeably.
Intrinsic measure: a numeric score that evaluates a clustering using only the input data and cluster assignments (no ground truth labels). Examples: Within‑cluster sum of squares (WCSS), Silhouette score, Davies–Bouldin index, Calinski–Harabasz index. These measure compactness and separation.
Extrinsic measure (also called external): a numeric score that compares clustering with a known correct partition (ground truth labels). Examples: Rand index, Adjusted Rand index (ARI), Mutual Information / Adjusted Mutual Information, Purity.
Elbow method: a graphical rule to pick k (number of clusters) using an intrinsic measure (commonly WCSS or model negative log‑likelihood). Plot the measure vs k; choose k at the point where the improvement slows sharply (look for an "elbow"). This is heuristic, not a theorem. Alternatives for choosing k include the Gap statistic and, for probabilistic models (e.g., GMM), information criteria such as AIC or BIC.
Exact relation used in many derivations: define the Total sum of squares (TSS) as the sum of squared distances of all points to the global mean, the Between‑cluster sum of squares (BSS) as the sum of squared distances between cluster centroids and global mean weighted by cluster sizes, and Within‑cluster sum of squares (WCSS) as the sum of squared distances of points to their cluster centroid. Then:
- TSS = BSS + WCSS (holds when squared Euclidean distance and mean centroids are used). Assumptions: Euclidean space, centroid defined as arithmetic mean, squared Euclidean distance.
Silhouette: for a point i, define a(i) = average distance from i to other points in the same cluster; for each other cluster C compute average distance from i to points in C; let b(i) be the minimum of those averages. The Silhouette value is s(i) = (b(i) - a(i)) / max(a(i), b(i)). Range: -1 (bad) to +1 (good). Averaging s(i) over all points gives the mean silhouette score for the clustering; averaging over the points of a single cluster gives that cluster's silhouette.
Davies–Bouldin index (DB): lower is better. For each cluster i, compute S_i (cluster scatter, e.g. average distance of points in i to its centroid). For cluster pair i,j compute M_ij = distance between centroids. For each i, find R_i = max_{j≠i} (S_i + S_j)/M_ij. Then DB = (1/k) sum_i R_i. Assumptions: positive inter‑centroid distances.
Calinski–Harabasz index (CH): higher is better. CH = (B/(k-1)) / (W/(n-k)) where B = between‑cluster variance (BSS), W = within‑cluster variance (WCSS), n = number of points, k = clusters. Assumes k>1 and n>k.
Rand index (RI): measures agreement between two partitions. Consider all unordered pairs of points. Count: a = number of pairs placed in same cluster in both partitions (true positives), b = number of pairs placed in different clusters in both partitions (true negatives). RI = (a + b) / C(n,2). Range: 0..1.
Adjusted Rand index (ARI): ARI corrects RI for chance. The standard formula uses the contingency table of two partitions and combinatorial counts; ARI has expected value 0 for random labeling and maximum 1 for perfect match. Use the combinatorial formula in the Formulas section.
Mutual Information (MI) and Adjusted Mutual Information (AMI): MI measures shared information between partitions; AMI adjusts for chance (AMI range 0..1 when using normalisation).
Purity: for each predicted cluster, assign it to the ground truth class with which it has largest overlap; Purity = (sum of maximum overlaps)/n. Simple, interpretable, but biased toward large k.
Diagrams to draw (if asked in exams):
- For the elbow method: draw x axis labeled k (number of clusters) from 1 to, say, 10; y axis labeled WCSS (or inertia). Plot a curve that decreases steeply then slowly; mark the elbow point where slope changes and draw a vertical dashed line at that k. Label axes, points and the elbow.
- For Silhouette: draw two small clusters; pick a sample point i, draw arrows showing a(i) (to same cluster points) and b(i) (to nearest other cluster). Annotate formula s(i).
Where I am unsure: numerical thresholds for "good" silhouette or how to pick elbow automatically—these are heuristics and dataset dependent. See verify list.
Formulas
x̄ = (1/n) * sum_{i=1..n} x_i — x̄ is the mean vector (centroid); units = same as x components; applies when computing centroids.
WCSS = sum_{clusters C} sum_{x in C} ||x - μ_C||^2 — WCSS: sum of squared Euclidean distances of points to their cluster centroid μ_C; units = (feature unit)^2; applies for squared‑Euclidean compactness.
TSS = sum_{i=1..n} ||x_i - μ||^2 — TSS: sum of squared distances to global mean μ; units = (feature unit)^2.
BSS = sum_{clusters C} |C| * ||μ_C - μ||^2 — BSS: weighted sum squared distance of centroids to global mean; units = (feature unit)^2.
TSS = BSS + WCSS — decomposition valid for squared Euclidean distance and centroid as mean.
a(i) = average_{y in cluster(i), y ≠ i} dist(i,y) — intra‑cluster mean distance for point i; units = feature units; requires cluster size ≥2.
b(i) = min_{clusters C ≠ cluster(i)} average_{y in C} dist(i,y) — nearest‑other cluster mean distance; units = feature units.
s(i) = (b(i) - a(i)) / max(a(i), b(i)) — Silhouette of point i; dimensionless; range [-1, 1].
DB = (1/k) * sum_{i=1..k} max_{j ≠ i} ( (S_i + S_j) / M_{ij} ) — Davies‑Bouldin index; S_i is average distance of points in cluster i to centroid; M_ij = distance between centroids i and j; lower is better.
CH = (B/(k-1)) / (W/(n-k)) — Calinski–Harabasz index; B = BSS, W = WCSS, n = number of samples; higher is better; requires n>k>1.
RI = (TP + TN) / C(n,2) — Rand Index; TP = number of point pairs placed together in both partitions; TN = number placed apart in both.
C(n,2) = n*(n-1)/2 — combinatorial choose two; unitless.
Let contingency table entries be n_ij (rows = ground clusters, columns = predicted clusters), a_i = sum_j n_ij, b_j = sum_i n_ij.
ARI = [ sum_{ij} C(n_ij,2) - ( sum_i C(a_i,2) * sum_j C(b_j,2) ) / C(n,2) ] / [ 0.5*( sum_i C(a_i,2) + sum_j C(b_j,2) ) - ( sum_i C(a_i,2) * sum_j C(b_j,2) ) / C(n,2) ] — Adjusted Rand Index; unitless; range [-1, 1] with expected value 0 for random labels and 1 for a perfect match.
Purity = (1/n) * sum_{j} max_i n_ij — Purity of predicted clusters w.r.t. ground truth; unitless in [0,1].
Notes: distances can be Euclidean or other metrics; many formulas assume Euclidean for centroid algebra.
Worked examples
Example 1 — Elbow with small 2D dataset (numerical, SI units: meters): Data (six points, units m): 1: (0,0) 2: (0,1) 3: (1,0) 4: (5,5) 5: (5,6) 6: (6,5)
Step A — k = 1 (all points in one cluster):
- Global centroid μ = ((0+0+1+5+5+6)/6, (0+1+0+5+6+5)/6) = (17/6, 17/6) ≈ (2.833333, 2.833333) m.
- Compute squared distances to μ and sum (showing results): point1: 16.055556 m^2 point2: 11.388889 m^2 point3: 11.388889 m^2 point4: 9.388889 m^2 point5: 14.722222 m^2 point6: 14.722222 m^2
WCSS(k=1) = 77.666667 m^2.
Step B — k = 2, natural split: cluster A = points 1,2,3; cluster B = points 4,5,6.
- Centroid μ_A = (0.333333, 0.333333) m; WCSS_A = 1.333333 m^2.
- Centroid μ_B = (5.333333, 5.333333) m; WCSS_B = 1.333333 m^2.
WCSS(k=2) = 2.666667 m^2.
Observation: WCSS drops from 77.67 to 2.67 when k changes 1→2, a very large reduction. For larger k the decrease is much smaller. The elbow is at k=2 — choose k=2. Final answer: WCSS(1)=77.666667 m^2, WCSS(2)=2.666667 m^2; elbow at k=2.
Example 2 — Silhouette values (same data and k=2 clustering above): Compute distances (Euclidean) and silhouette for point 1 (0,0):
- a(1) = average distance to points in same cluster (points 2 and 3): (1 + 1)/2 = 1.000000 m.
- distances to other cluster points: 7.071068 m, 7.810250 m, 7.810250 m; b(1) = average = 7.563856 m.
s(1) = (7.563856 - 1.000000) / 7.563856 = 0.8678. Compute similarly for points 2 and 3; their silhouettes ≈ 0.825 and 0.825. Points 4–6 give similar high values. Average silhouette ≈ 0.84 → indicates a very good clustering (close, well separated). Final: average silhouette ≈ 0.84 (high).
Example 3 — Adjusted Rand Index (ARI) numeric example: Ground truth clusters: G1 = {1,2,3}, G2 = {4,5,6}. Predicted clustering P1 = {1,2,3,5}, P2 = {4,6} (point 5 misclassified into cluster1). Contingency table n_ij:
- n_11 = 3, n_12 = 0
- n_21 = 1, n_22 = 2
Compute combinatorial sums: C(3,2)=3, C(2,2)=1, C(1,2)=0, C(0,2)=0.
- sum_{ij} C(n_ij,2) = 3 + 0 + 0 + 1 = 4.
- sum_i C(a_i,2) (ground) = C(3,2)+C(3,2)=3+3=6.
- sum_j C(b_j,2) (predicted) = C(4,2)+C(2,2)=6+1=7.
- C(n,2) = C(6,2) = 15.
Plug into ARI formula (numbers):
- Numerator = 4 - (6*7)/15 = 4 - 42/15 = 4 - 2.8 = 1.2.
- Denominator = 0.5*(6+7) - (6*7)/15 = 6.5 - 2.8 = 3.7.
ARI = 1.2 / 3.7 ≈ 0.3243. Rand index for same example: agreements = 10 →RI = 10/15 = 0.6667. Interpretation: ARI ≈ 0.32 shows modest agreement after adjusting for chance; RI overestimates agreement because it does not correct for chance.
Common mistakes
- Using purity to compare clusterings with different k: purity increases with k and is biased toward large k.
- Interpreting a small elbow as a strict rule: elbow is heuristic; there may be no clear elbow.
- Confusing Rand index and Adjusted Rand index: ARI corrects for chance; report ARI when comparing across datasets.
- Forgetting
n-kandk-1denominators in CH index — leads to wrong scaling.
For your exam
Typical question types:
- Definitions and short notes: define WCSS, silhouette, intrinsic vs extrinsic measures.
- Derivations: prove TSS = BSS + WCSS under Euclidean squared distance; derive silhouette formula and show its range.
- Numericals: compute WCSS for small points and use the elbow rule; compute silhouette for given clusters; compute ARI from a contingency table.
- Diagrams: draw elbow plot and illustrate silhouette distances for a sample point.
What full‑marks answers include:
- Clear definitions with bold term named and assumptions stated (e.g., Euclidean, centroids as means).
- For derivations, state assumptions, write algebraic steps (expand squared sums), and conclude TSS = BSS + WCSS.
- For numericals, show intermediate calculations, units, final numeric values and interpretation (e.g., elbow at k=2, silhouette ≈ 0.85 → good).
- For external measures, include contingency table, combinatorial counts, and numeric ARI with interpretation.
Quick check
Q1: What is the difference between intrinsic and extrinsic cluster evaluation? Q2: Write the silhouette formula for a point i and its possible range. Q3: In the ARI combinatorial formula, what does C(n,2) mean?
Answers: Intrinsic uses only data and cluster labels (no ground truth); extrinsic compares clustering to known labels. / s(i) = (b(i) - a(i)) / max(a(i), b(i)), range [-1, 1]. / C(n,2) = n*(n-1)/2 (number of unordered pairs).
Finished this topic? Mark it so your progress, study plan and readiness keep up.
Stuck on something here?