Module 7 — Clustering
Sources: Lec 16 — Overview of Data Clustering; Lec 17 — Partitional Clustering; Lec 18 — Hierarchical Clustering (incl. DBSCAN); Lec 19 — Evaluation Criteria for Clustering.
Notation. ; clusters ; centroid ; distance (default Euclidean).
C35. What Clustering Is: Formulation, Types, and Convexity
Intuition
Group objects so that members of a group resemble each other and differ from other groups — without anyone telling you the groups. Quality depends entirely on how “similar” is measured.
Formal definition
A clustering of into clusters is a partition satisfying (i) ; (ii) for ; (iii) .
Types. Hierarchical (a tree of clusters, a dendrogram; agglomerative = bottom-up merging, divisive = top-down splitting) and partitional (a fixed, pre-chosen number of clusters).
Partitional loss (lecture): and the aim is a partition with for all partitions .
Mathematical consequence: clusters are convex
For Euclidean , a point is assigned to rather than iff , i.e. a half-space (a set bounded by a hyperplane — convex). The intersection of such half-spaces is convex. So the optimum of always produces convex-shaped clusters, which may not match the structure you want (ring-shaped, crescent-shaped clusters).
Key insights
- The number of partitions of points into exactly 2 non-empty clusters is (Stirling number ) — exhaustive search is hopeless in general.
- Clustering is unsupervised: validity must be judged by external labels (C41–C42) or by internal criteria.
Worked examples
Example 1 — Very Easy
- Problem: For which are valid partitions? (i) ; (ii) ; (iii) ; (iv) .
- Asked: Validity.
- Concept: Partition axioms.
- Approach: Test the three conditions.
- Solution: (i) valid. (ii) is in both ⇒ violates disjointness. (iii) is missing ⇒ violates covering. (iv) an empty cluster ⇒ violates non-emptiness.
- Final answer: Only (i).
- Key lesson: Hard clustering ⇒ each point belongs to exactly one non-empty cluster.
Example 2 — Easy
- Problem: (1-D). Compute with for and .
- Asked: .
- Concept: Partitional loss.
- Approach: Centroids are means.
- Solution: : : ; : ⇒ . : : ; : ⇒ .
- Final answer: .
- Key lesson: Good clusterings have small loss.
Example 3 — Moderate
- Problem: How many ways can labelled points be split into exactly 2 non-empty clusters? How many partitions in total (any )?
- Asked: Counts.
- Concept: Combinatorics of partitions.
- Approach: Pin one point; others choose side.
- Solution: Fix point in cluster A; each other point is in A or B: assignments; exclude “all in A” (B empty) ⇒ . Total over all : Bell number ().
- Final answer: and .
- Key lesson: The search space grows super-exponentially.
Example 4 — Hard
- Problem: Points (an “outer” cluster) and (an “inner” cluster). The desired clustering is inner vs outer. Compute () for it and compare with the best two-cluster partition.
- Asked: Is the desired clustering optimal?
- Concept: Optimum of is convex-shaped.
- Approach: Enumerate the partitions.
- Solution: Desired: : ⇒ ; : ⇒ . . Enumerating all 15 partitions the minimum is for and (centroids and : ). Next best values are . The desired partition () is not even in the top three.
- Final answer: Desired ; optimal with interval clusters.
- Key lesson: A non-convex cluster (outer points surrounding the inner ones) can never be an optimum of this criterion.
Example 5 — Very Hard
- Problem: Concentric “rings”: inner ; outer . (a) Show that for the desired ring partition both centroids coincide at the origin. (b) Compute (Euclidean distances) for the desired partition and for the half-space partition ” vs ”. (c) What is the optimum over all 127 two-cluster partitions?
- Asked: Three computations.
- Concept: Half-space limitation.
- Approach: Centroids; sum distances.
- Solution: (a) Inner mean ; outer mean . Equal centroids ⇒ the bisector is empty/undefined — a centroid-based assignment cannot even represent nested clusters. (b) Desired: inner distances ; outer ⇒ . Half-space: left , ⇒ ; right (6 points) : ; ; each; each; sum ⇒ . (c) Exhaustive minimum (isolating one outer point).
- Final answer: Desired ring partition is worse than a plain half-space split and than the optimum .
- Key lesson: For non-convex clusters, use density-based (C40) or single-linkage methods, not centroid-based ones.
Common mistakes
- Allowing overlapping or empty clusters in a hard clustering.
- Assuming the optimum of finds “natural” shapes.
Exam traps
- Partitional ⇒ fixed in advance; hierarchical ⇒ no need for in advance (but a cut level or stopping criterion is needed).
- gives convex clusters.
Connections
C36–C40 (algorithms), C41–C42 (evaluation), C17 (assignment = minimum distance to centroids).
Mastery checklist
- State the three partition axioms.
- Define the partitional loss .
- Explain why yields convex clusters.
C36. The k-Means (Lloyd) Algorithm
Intuition
Alternate two easy steps: (1) assign every point to its nearest centre; (2) move every centre to the mean of its points. Each step lowers (or keeps) the total squared distance, so the process settles.
Algorithm (Lloyd, as in the lecture)
- Choose initial centroids randomly from the data. Set .
- Assign: .
- Update: .
- Stop if or (iteration cap); else and go to step 2. (MacQueen’s variant updates a centroid immediately after each single reassignment.)
Mathematical analysis
With the squared Euclidean distance the objective is .
- Update step is optimal for fixed assignments: (the mean); second derivative ⇒ minimum.
- Assignment step is optimal for fixed centroids (each point picks the smallest term).
- Hence never increases; with finitely many partitions the algorithm terminates at a local minimum.
- Cost per iteration (linear in ).
Limitations
must be given; sensitive to initial seeds and to the distance function; local optima; sensitive to outliers (the mean); convex clusters only.
Worked examples
Example 1 — Very Easy
- Problem: , , initial centroids and . Do one assignment step.
- Asked: Clusters after step 2.
- Concept: Assignment.
- Approach: Nearest centroid.
- Solution: : distances vs ⇒ . : vs ⇒ . : vs ⇒ . : vs ⇒ ; similarly .
- Final answer: , .
- Key lesson: Poor seeds give a poor first partition.
Example 2 — Easy
- Problem: Continue Example 1 to convergence; report after each update.
- Asked: Final clusters and .
- Concept: Lloyd iterations.
- Approach: Alternate.
- Solution: Update 1: , ; . Assign 2: ; : ; : ; : ; . Update 2: , ; . Assign 3: unchanged ⇒ stop.
- Final answer: ; .
- Key lesson: decreases monotonically.
Example 3 — Moderate
- Problem: 2-D points , , seeds and . Run to convergence.
- Asked: Final clusters, centroids, .
- Concept: Lloyd in 2-D.
- Approach: Euclidean distances.
- Solution: : , ⇒ . : , ⇒ . , ; , . Re-assign: to : ; to : ✓; : to vs to ✓. No change. .
- Final answer: , , .
- Key lesson: Converged when centroids stop moving.
Example 4 — Hard
- Problem: , . (a) Seeds . (b) Find the global optimum. Compare .
- Asked: Local vs global optimum.
- Concept: Initialisation sensitivity.
- Approach: Run Lloyd; enumerate contiguous 3-partitions.
- Solution: (a) Assign: ; ; (nearest centroid : distances vs to : ). Update: — unchanged on re-assignment ⇒ converged. . (b) Best partition : (centroids ).
- Final answer: Seeds give (local optimum); the global optimum has .
- Key lesson: k-means converges, but not necessarily to the best answer — run several seeds.
Example 5 — Very Hard
- Problem: Prove that Lloyd’s algorithm (squared Euclidean) never increases and terminates; then verify numerically on Example 2.
- Asked: Proof and check.
- Concept: Coordinate descent.
- Approach: Two-step monotonicity.
- Solution: Let . Assign step: with fixed, moving a point from to the nearest replaces by ⇒ does not increase. Update step: with fixed, the mean minimises each cluster’s sum of squares (derivative above) ⇒ does not increase. The sequence is bounded below. Because the number of partitions is finite and strictly decreases whenever the partition changes, no partition repeats ⇒ termination. Check: Example 2 gave (after first update) then ✓ decreasing, then unchanged.
- Final answer: Monotone decreasing, finite termination at a local minimum.
- Key lesson: The proof requires the mean — it is the minimiser only for squared distances (for the minimiser is the median, giving k-medians/k-medoids, C38).
Common mistakes
- Using -means with arbitrary distances and still taking the mean.
- Stopping after one iteration.
Exam traps
- Stop rule: centroids unchanged for consecutive iterations (or iteration cap).
- Complexity is linear in but iterations may be many.
Connections
C17 (minimum-distance), C35, C37–C38, PCA preprocessing (C46).
Mastery checklist
- Run Lloyd’s algorithm by hand.
- Prove monotone decrease.
- Explain local optima and how to mitigate them.
C37. Bisecting k-Means and the Buckshot Algorithm
Intuition
Two repairs to k-means. Bisecting: build clusters top-down by repeatedly splitting the largest cluster with 2-means (deterministic structure, near-uniform sizes). Buckshot: get good seeds by clustering a small random sample hierarchically first.
Algorithms
Bisecting k-means: start with all data as one cluster; while fewer than clusters, pick the largest cluster and split it into two with () k-means. Buckshot: (1) draw a random sample of size ; (2) cluster the sample by (agglomerative) hierarchical clustering down to clusters; (3) use their centroids as seeds for ordinary k-means on all points.
Properties
- Bisecting produces clusters of almost uniform size: good when true clusters are balanced, poor when sizes differ greatly. It still needs and 2-means seeds.
- Buckshot: sample hierarchical cost small; repeated runs give different partitions; poor if the sample is unrepresentative; still needs .
Worked examples
Example 1 — Very Easy
- Problem: Current clusters have sizes . Which does bisecting k-means split next?
- Asked: Choice.
- Concept: “Largest cluster” rule.
- Approach: Max size.
- Solution: The size-10 cluster.
- Final answer: The size-10 cluster.
- Key lesson: Selection is by size, not by within-cluster scatter.
Example 2 — Easy
- Problem: Buckshot sample sizes for () and ().
- Asked: Two sizes.
- Concept: .
- Approach: Compute.
- Solution: ; .
- Final answer: and .
- Key lesson: The sample is a vanishing fraction of the data for large ( in the second case).
Example 3 — Moderate
- Problem: Bisecting k-means with on (assume each 2-means finds the optimal split).
- Asked: Final clusters.
- Concept: Bisecting procedure.
- Approach: First split, then largest.
- Solution: 2-means on all 8: best contiguous split (; the competing split has ). Largest cluster = the six-point one ⇒ 2-means: (). Three clusters now.
- Final answer: .
- Key lesson: Splitting the largest cluster recovers the true structure here.
Example 4 — Hard
- Problem: Buckshot on , : sample size ; suppose the sample is . Cluster it by single-linkage to 2 clusters, then run k-means from those centroids.
- Asked: Seeds and final result.
- Concept: Buckshot.
- Approach: Hierarchical on the sample.
- Solution: Sample distances: –: ; –: ; –: . Single-linkage merges then ⇒ clusters with centroids and (seeds). k-means on all 8: ; . Update: and ; assignments unchanged ⇒ converged. .
- Final answer: , .
- Key lesson: Seeds from a hierarchical pass avoid pathological starts.
Example 5 — Very Hard
- Problem: Data , (as in C36 Ex. 4). Compare bisecting k-means with plain k-means seeded .
- Asked: of each.
- Concept: Bisecting as deterministic top-down.
- Approach: Optimal 2-splits.
- Solution: First split of all six: contiguous options: : ; : ; others larger ⇒ choose . Largest = the 4-point cluster: splits : ; : ⇒ choose the first. Final: : (global optimum). Plain k-means from the unlucky seeds: .
- Final answer: Bisecting vs plain k-means .
- Key lesson: Top-down splitting can avoid bad seeds — but is not guaranteed optimal in general.
Common mistakes
- Splitting the cluster with largest variance (the lecture’s rule is largest size).
- Taking a sample of size .
Exam traps
- Bisecting ⇒ near-uniform sizes; fails with very unequal true sizes.
- Buckshot needs and a hierarchical step on points.
Connections
C36, C39.
Mastery checklist
- Execute bisecting k-means.
- Compute Buckshot’s sample size.
- State the weaknesses of each.
C38. k-Medoids
Intuition
The mean can be dragged away by an outlier and need not be a real data point. A medoid is an actual data point near the centre — robust, and usable with any dissimilarity.
Definitions (lecture)
- Medoid (minimax form): for each compute ; the medoid is the point achieving . Cost .
- Approximation: the member closest to the mean of the set: . Cost .
- (The lecture also describes the medoid as the member with minimal average distance to all others — the standard textbook definition; the three definitions often, but not always, coincide.) The rest of the algorithm is k-means with medoids in place of means.
Key insights
- Robust to outliers; the centre is always a data point.
- Same limitations as k-means ( fixed, seeds).
Worked examples
Example 1 — Very Easy
- Problem: Medoid (closest-to-mean) of .
- Asked: Medoid and mean.
- Concept: Approximation.
- Approach: Mean, then nearest member.
- Solution: Mean . Distances: ⇒ nearest is .
- Final answer: Mean , medoid .
- Key lesson: The mean is pulled by ; the medoid is not.
Example 2 — Easy
- Problem: For compute the minimax and average-distance medoids.
- Asked: Two medoids.
- Concept: Definitions.
- Approach: Table.
- Solution: Max distances: , , , ⇒ minimax medoid . Average distances: ; ; ; ⇒ tie between and .
- Final answer: Minimax: ; average: or .
- Key lesson: Definitions can disagree on ties; state which you use.
Example 3 — Moderate
- Problem: Cluster : mean, approximate medoid, and the distance of a new point to each.
- Asked: Compare centres.
- Concept: Outlier robustness.
- Approach: Compute.
- Solution: Mean . Distances of members to : ⇒ approximate medoid . Distance of : to the mean ; to the medoid .
- Final answer: Mean vs medoid .
- Key lesson: The mean is far from every real member.
Example 4 — Hard
- Problem: For compare the number of distance evaluations for the exact minimax medoid vs the mean-based approximation (per cluster).
- Asked: Counts.
- Concept: Complexity.
- Approach: Pairs vs points.
- Solution: Exact: all ordered pairs, (or distinct). Approximate: compute the mean () then distances.
- Final answer: vs distances.
- Key lesson: Hence the approximation in practice, at the price of exactness.
Example 5 — Very Hard
- Problem: , , . Start with medoids and run to convergence; report cost.
- Asked: Final medoids and clusters.
- Concept: k-medoids iteration.
- Approach: Assign; recompute medoids (minimising total distance).
- Solution: Assign: , (e.g. : vs ✓), . New medoids: for total distance to is (vs for ) ⇒ ; for ⇒ ; . Re-assign: unchanged. Cost .
- Final answer: Medoids ; clusters ; cost .
- Key lesson: The outlier gets its own cluster rather than distorting a centroid.
Common mistakes
- Using the mean and calling it a medoid.
- Believing the medoid must minimise squared distance (that is the mean).
Exam traps
- Medoid is a data point; mean need not be.
- Both k-means and k-medoids need and seeds.
Connections
C36, robust statistics (median), C37.
Mastery checklist
- Compute a medoid by the three definitions.
- Explain outlier robustness.
- State the cost of exact vs approximate medoids.
C39. Agglomerative Hierarchical Clustering: Single, Complete, Average Linkage
Intuition
Start with every point alone; repeatedly merge the two closest clusters; record the merges in a tree (dendrogram). “Closest” for sets of points needs a definition — that choice is the linkage.
Algorithm
- Every point is a singleton cluster. 2. Compute distances between all pairs of clusters. 3. Merge the closest pair. 4. Repeat 2–3 until one cluster (or until the desired number of clusters). Cutting the dendrogram at a height gives a flat clustering.
Linkages (lecture)
For clusters , : Update rule after merging into , for another cluster (Lance–Williams): single ; complete ; average .
Behaviour
- Single: can follow chains of close points ⇒ long, straggly clusters; the chaining effect: two clusters joined by a thin bridge of noise points get merged.
- Complete: compact, roughly spherical clusters; sensitive to outliers.
- Average: in between.
- Naive complexity time, memory. Choosing where to stop is the main practical difficulty.
Worked examples
Example 1 — Very Easy
- Problem: , (1-D). Compute the three linkage distances.
- Asked: Three numbers.
- Concept: Linkage definitions.
- Approach: All cross distances: .
- Solution: Single ; complete ; average .
- Final answer: .
- Key lesson: Single average complete always.
Example 2 — Easy
- Problem: Points . Give the merge sequence and heights for single, complete, average.
- Asked: Three dendrograms.
- Concept: Algorithm.
- Approach: Merge closest pair each time.
- Solution: All three first merge (height ), then (height ). Next: single: –; complete: ; average: . Then joins : single (–); complete ; average .
- Final answer: Heights — single: ; complete: ; average: .
- Key lesson: Same merge order here, different heights.
Example 3 — Moderate
- Problem: Points (doubling gaps). Merge heights for the three linkages.
- Asked: Heights.
- Concept: Height behaviour.
- Approach: Sequential merges (all produce , then , then , then ).
- Solution: Single: . Complete: . Average: .
- Final answer: Single ; complete ; average .
- Key lesson: Complete-link heights are the cluster diameters.
Example 4 — Hard
- Problem: Points . Find the 3-cluster partition from each linkage.
- Asked: Three partitions.
- Concept: Linkages can disagree.
- Approach: Run three merges each.
- Solution: Pairwise gaps: . Single: merge at 2; at 5; joins at 6 ⇒ 3 clusters . Complete: at 2; at 5; next smallest complete distance: (vs , ) ⇒ . Average: at 2; at 5; vs ⇒ merge with ⇒ .
- Final answer: Three different partitions.
- Key lesson: The linkage is the assumption about what a cluster looks like.
Example 5 — Very Hard
- Problem: Two blobs and connected by a sparse bridge . Compare single and complete linkage; what does each give for 3 clusters?
- Asked: Chaining demonstration.
- Concept: Chaining effect.
- Approach: Merge heights.
- Solution: Single: merges at height build and ; then every bridge gap is (2–4, 4–6, 6–8, 8–10), so all remaining merges happen at height 2 — the dendrogram cannot tell the bridge from the blobs; a 3-cluster cut (after 6 merges) depends on tie-breaking and may give — the bridge is absorbed into a blob. Complete: merge heights in order: (), (), (), (), (), (adds to ), (joins with ), (final merge). A 3-cluster cut gives — the true structure.
- Final answer: Single linkage chains through the bridge; complete linkage recovers three clusters.
- Key lesson: Single linkage is fragile under noise bridges; complete linkage is robust (but outlier-sensitive).
Common mistakes
- Re-using the original distances after a merge (must recompute/update).
- Forgetting ties.
Exam traps
- Single = min, complete = max, average = mean of all cross distances.
- Hierarchical methods need a halting criterion (the lecture’s main limitation).
Connections
C35, C37 (Buckshot step), C40 (DBSCAN avoids chaining).
Mastery checklist
- Compute all three linkages for two sets.
- Build a dendrogram by hand.
- Explain chaining.
C40. Divisive Clustering and DBSCAN
Intuition
Divisive: start with everything in one cluster and split — the mirror image of agglomerative. DBSCAN: clusters are dense regions separated by sparse regions; points in sparse regions are noise. This finds arbitrarily shaped clusters and does not need .
Divisive clustering (lecture)
Start with the whole data set as one cluster. At each step choose one existing cluster (generally the one with the least overall similarity) and split it into two. Stop when only singletons remain or a halting criterion is met. Limitation: choosing the halting point for unknown data.
DBSCAN (Ester et al. 1996; as in the lecture)
Parameters: neighbourhood radius , minimum count .
- Neighbourhood of each point: (it includes itself).
- Merge and into if , and .
- Repeat until no merge occurs. Points belonging to no merged neighbourhood are noise. (In common terminology: a point with is a core point; non-core points inside a core’s neighbourhood are border points.)
Key insights
- No ; detects noise; can find non-convex clusters.
- Avoids chaining because bridging requires dense neighbourhoods.
- Hard to choose and ; a single global density can fail when densities vary.
Worked examples
Example 1 — Very Easy
- Problem: Divisive step: a cluster . Which split minimises the sum of within-cluster scatter (2-means)?
- Asked: The split.
- Concept: Divisive splitting.
- Approach: Split into two groups.
- Solution: : ; any other contiguous split is larger (e.g. has ).
- Final answer: .
- Key lesson: One divisive step can be a 2-means call.
Example 2 — Easy
- Problem: , , . Compute , the core points and the clusters.
- Asked: DBSCAN output.
- Concept: Lecture’s algorithm.
- Approach: Count neighbours within (including self).
- Solution: : ; ; ; ; ; ; ; . Cores (): . ⇒ merge . alone . Point is in no neighbourhood ⇒ noise.
- Final answer: Clusters and ; noise .
- Key lesson: Border points join through cores.
Example 3 — Moderate
- Problem: Points , bridge , , , . Output?
- Asked: Clusters.
- Concept: Core/neighbourhood merging.
- Approach: Neighbour counts.
- Solution: : ; ; ; ; and symmetric for . Cores: ; ; . overlap pairwise ⇒ one cluster ; stands alone ⇒ ; likewise. No noise.
- Final answer: Three clusters: , bridge, .
- Key lesson: The bridge is separated from the blobs because the gaps ( and ) exceed .
Example 4 — Hard
- Problem: Same points. (a) ; (b) . Outputs?
- Asked: Parameter sensitivity.
- Concept: Choosing .
- Approach: Recount.
- Solution: (a) Bridge points have no neighbour within ( each) ⇒ not core, in no core neighbourhood ⇒ noise; clusters and remain. (b) : and both and intersect ⇒ merges with the bridge; similarly bridge with ⇒ everything becomes one cluster.
- Final answer: (a) 2 clusters + 3 noise points; (b) 1 cluster.
- Key lesson: controls whether sparse bridges are noise, separate clusters or merged.
Example 5 — Very Hard
- Problem: Explain, using this data, why DBSCAN avoids the chaining that plagues single linkage, and when it would still chain.
- Asked: Argument.
- Concept: Density vs distance.
- Approach: Compare merge conditions.
- Solution: Single linkage merges and the bridge once the gap is the smallest remaining distance, regardless of how thin the bridge is. DBSCAN merges two neighbourhoods only if both are dense ( points) and overlap. With the gap exceeds , so nothing connects; even if a single point lay in the gap, of that point would be small (1–2), failing . It chains only when the bridge itself is dense (as with : points of the bridge then have neighbours and neighbourhoods overlap with those of ).
- Final answer: DBSCAN requires density, not just proximity; a dense bridge defeats it.
- Key lesson: The pair encodes “how dense is a cluster”.
Common mistakes
- Forgetting the point itself in .
- Counting border points as cores.
Exam traps
- Noise = points not in any merged neighbourhood.
- No needed, but and are.
Connections
C39 (chaining), C35 (non-convex clusters).
Mastery checklist
- Run DBSCAN by hand.
- Contrast with single linkage.
- Explain the effect of and .
C41. Cluster Evaluation I: the F-measure
Intuition
If class labels exist, ask how well each class is recovered by some cluster: use the recall/precision of its best-matching cluster, then weight by class size.
Formal definition
= categories ( of them), = clusters (), points; = size of category , = size of cluster , = overlap. Larger is better; .
Key insights
- Same formula as C11 with “category” = positive class and “cluster” = predicted group.
- Max over clusters: each category is matched to its best cluster (a cluster may be matched by several categories).
- Weakness: a single big cluster gets a high (Example 5).
Worked data used in Examples 2–4
. Contingency table (rows = categories, columns = clusters):
Worked examples
Example 1 — Very Easy
- Problem: Category with members; cluster with ; overlap . Recall, precision?
- Asked: .
- Concept: Definitions.
- Approach: Divide.
- Solution: Recall ; precision .
- Final answer: .
- Key lesson: Recall divides by the category size, precision by the cluster size.
Example 2 — Easy
- Problem: for () and ().
- Asked: Two values.
- Concept: .
- Approach: Harmonic mean.
- Solution: : . : , , .
- Final answer: and .
- Key lesson: Only the best-matching cluster counts toward .
Example 3 — Moderate
- Problem: Compute .
- Asked: Category-wise best .
- Concept: .
- Approach: Compute the full matrix.
- Solution: : , , ⇒ . (): : ; : ; : ⇒ . (): : ; ⇒ .
- Final answer: .
- Key lesson: Category 3 is recovered best.
Example 4 — Hard
- Problem: The overall for the table, and how it changes if and are merged.
- Asked: and .
- Concept: Weighted average; merging clusters.
- Approach: .
- Solution: . Merge (): overlaps , , . : vs : ; vs merged: ⇒ ⇒ . : vs merged: ; vs : ⇒ . : vs merged: ; vs : ⇒ . .
- Final answer: ; after merging .
- Key lesson: Merging clusters lowers precision, hence .
Example 5 — Very Hard
- Problem: Two categories of 50 points each. Compute for (a) perfect clustering, (b) one cluster containing everything, (c) singleton clusters. Comment.
- Asked: Three values.
- Concept: Degenerate clusterings.
- Approach: Per-category best match.
- Solution: (a) ⇒ ⇒ . (b) , : , , ⇒ . (c) best cluster is a singleton: : , , ⇒ .
- Final answer: , , .
- Key lesson: The trivial one-cluster solution scores surprisingly high (); F rewards recall too generously — compare with the number of clusters and use NMI (C42) as a complement.
Common mistakes
- Averaging over all clusters instead of taking the max.
- Weighting by cluster size instead of category size.
Exam traps
- (category weights).
- when .
Connections
C11, C42.
Mastery checklist
- Compute .
- Explain the max over clusters.
- State the one-cluster weakness.
C42. Cluster Evaluation II: Normalised Mutual Information (NMI)
Intuition
Knowing the cluster of a point should tell you something about its category. Mutual information measures how many bits the cluster reveals about the category; dividing by the entropies puts it on a scale.
Formal definition (Strehl & Ghosh)
Conventions: ; every category and cluster non-empty. The log base cancels in the ratio.
Properties
- ; iff and are independent ().
- ; .
- Invariant to relabelling clusters.
Derivation: under independence
If then , for every term. ∎
Worked examples
Example 1 — Very Easy
- Problem: Perfect clustering of two balanced categories (, , off-diagonals 0). NMI?
- Asked: NMI.
- Concept: .
- Approach: Compute (log base 2).
- Solution: . . .
- Final answer: .
- Key lesson: A perfect clustering has NMI 1.
Example 2 — Easy
- Problem: Same categories but each cluster has 25 of each category (). NMI?
- Asked: NMI.
- Concept: Independence.
- Approach: .
- Solution: Every log term ⇒ ⇒ .
- Final answer: .
- Key lesson: Cluster labels carrying no information give NMI 0.
Example 3 — Moderate
- Problem: , table (rows categories, columns clusters). Compute NMI (bits).
- Asked: NMI.
- Concept: Full formula.
- Approach: .
- Solution: Diagonal terms: (twice). Off-diagonal: (twice). . ⇒ .
- Final answer: .
- Key lesson: Off-diagonal terms contribute negatively (cells less populated than independence predicts).
Example 4 — Hard
- Problem: NMI (bits) for the table of C41.
- Asked: NMI.
- Concept: Full computation.
- Approach: Sum the nine terms; entropies of , .
- Solution: . . : : ; : ; : ; : ; : ; : ; : . bits. .
- Final answer: (alongside ).
- Key lesson: Different criteria give different scales; NMI is stricter than F here.
Example 5 — Very Hard
- Problem: Two categories of 50. Show that placing every point in its own cluster () gives and evaluate it; then comment.
- Asked: Formula and value.
- Concept: Bias toward many clusters.
- Approach: If each cluster is a singleton, and the cluster determines the category.
- Solution: for the unique category of the point. . . . Here (bits) , ⇒ .
- Final answer: for the meaningless singleton clustering.
- Key lesson: NMI is not zero for over-clustering; use it with the number of clusters in mind (complements F, which penalises singletons heavily: ).
Common mistakes
- Forgetting .
- Using instead of .
Exam traps
- Denominator is (geometric mean).
- NMI(S,S)=1.
Connections
Entropy and information gain (C4), F-measure (C41).
Mastery checklist
- Compute and NMI from a contingency table.
- Show under independence.
- Discuss NMI and F together.