Hierarchical Clustering, merge by merge


Dataset
Data points 10 to 30 — press Enter or click away to redraw
Linkage
Run
Cluster threshold

The one step. There is no k to choose and nothing to initialize. Every point starts as its own cluster, and the only move is: find the two closest clusters and join them. Do that n−1 times and everything is in one cluster. Each line on the scatter is one join, drawn between the exact pair of points whose distance set the cost: the closest pair under Single, the farthest pair under Complete — so the line you see is always as long as the height in the status line. (Average is the mean over every cross pair, so no single pair defines it; there the line just marks where the two groups come closest.) The tree below records the same joins at the height each one cost. Since one run produces every grouping from n clusters down to 1, you pick k afterwards by cutting the tree — drag the Cluster threshold slider and watch the dashed line slide, without anything being recomputed. The threshold is a height: every join costing that much or less is accepted, everything dearer is refused, and the number of clusters is whatever falls out. Every dataset scales to whatever the Data points box says, so you can walk a 10-point tree by hand, or push it to 30 for a fuller picture.

Distance between two points is obvious. Distance between two groups is a choice — that choice is the linkage, and it is the only thing that ever changes.

Three things worth trying. (Counts below are for the default 10 points. Change the box and the counts change, but the behavior does not.)

1. Bridge, threshold dragged down to 2 clusters, flipping between Single and Complete. Single linkage walks straight across the stepping stones and welds the two blobs into one cluster of 9, leaving the lone outlier as the entire second cluster — that is chaining, and it is what “nearest pair” buys you. Complete linkage refuses, because joining across the bridge would make one very wide cluster, so it splits the data down the middle instead: 4 and 6. Neither answer is the one you wanted — they fail in opposite directions.

2. Two rings, threshold down to 2 clusters. (Set Data points to 14 first — see the note at the end of this paragraph.) Single linkage splits them perfectly — 4 points and 10, exactly the inner ring and the outer one — because a ring is well connected to itself all the way round, and connectivity is all single linkage looks at. Now switch to Complete: you get 7 and 7, and the split is not between the rings at all — one cluster is the whole inner ring plus three points off the outer one, the other is the seven that were left. That rule asks “how compact would the merged cluster be?”, and a fat wedge is more compact than a thin ring, so it cuts across both rings rather than between them. This is the same shape k-means cannot find either. (Two rings needs 12 points or more to hold together. At the default 10 there are only 7 points on the outer ring, its own gaps are wider than the gap between the rings, and even single linkage chains across — you get 1 and 9 instead of the two rings.)

3. Three blobs, and step through with Merge once. Watch the height in the status line: it creeps up while points inside a blob are joining, then the last two merges cost roughly ten times a typical one, more with complete linkage. That jump is the signal — a tall gap in the tree means a real cluster boundary, and it is how you read k off a dendrogram instead of guessing it. Park the threshold in that gap and you get 3 clusters; here every linkage agrees, and all three recover the blobs exactly, 4, 3 and 3 points. Well-separated data is easy; the linkage only starts to matter when it is not.

Which linkage does what? All three run the identical loop — they differ only in how the distance between two groups is defined. That one line is the entire difference between these methods.
LinkageDistance between groups A and BWhat it prefers, and where it breaks
Single the closest pair
min d(a, b)
Follows shapes: rings, snakes and crescents come out whole. But one near pair is enough to fuse two groups, so a thin bridge of points welds them together — chaining. Try it on Bridge.
Complete the farthest pair
max d(a, b)
Asks how wide the merged cluster would be, so it produces compact, similarly sized balls. Splits genuinely elongated clusters down the middle, and one far-flung point can hold a whole merge back.
Average the mean over all
cross pairs
The compromise, and usually the safe default: much harder to chain than single, much less brittle than complete. The price is that there is no simple geometric story to tell about what it is optimizing.
Reading the height scale. The number at the top right of the tree panel is the cheapest merge the current cut is refusing — the scale grows as you merge, so the tree always fills the panel. Watch it jump when two whole groups finally join: that is the same tall gap you are looking for when you decide where to cut.