Clustering Fundamentals
Agglomerative clustering is a family of algorithms that starts with each point as its own cluster.
Groups Without a Known Answer
Imagine you are handed a pile of data points and asked to sort them into groups, but nobody has told you how many groups to expect or what each group should look like. A natural first move is to ask which points belong together, and then to keep combining the most similar groups until the result is manageable. Agglomerative clustering is a family of algorithms built on exactly this idea. The word agglomerative refers to the act of gathering things together, and that is the direction the whole procedure moves in.
What do you think happens?
Before any merging happens, how many clusters does an agglomerative algorithm start with if there are twenty data points?
Reveal answer
20
Every algorithm in the family begins by declaring each point to be its own cluster. Twenty points therefore give twenty clusters, each containing exactly one point. Nothing has been grouped yet.
Starting With Every Point Alone
The starting arrangement is the foundation of the whole method. Each algorithm in the agglomerative family begins in the same way: every point is declared to be its own cluster. A cluster containing a single point is still a cluster, so the algorithm has a valid arrangement from its very first moment, even though no grouping has occurred.
Comparing the two arrangements shows what the algorithm is doing. The first arrangement contains five clusters that each hold one point. The second contains three clusters, and two of them now hold more than one point. Each merge combined two existing clusters, so the groups grew while the total number of clusters fell.
The Repeated Merge Step
From the starting arrangement, the algorithm repeats one operation. It finds the two most similar clusters that currently exist and merges them into a single cluster. A merge always reduces the number of clusters by exactly one, so the count shrinks step by step. The procedure does not jump to a final answer. It moves through a sequence of intermediate arrangements, each one slightly coarser than the one before.
Notice that the cluster count is the only thing this progression tracks. What decides which two clusters are merged at each step is a separate question, and that question is where linkage criteria come in. In the example above, the choice of A and B first, then D and E, is an assumed outcome of a similarity measure, not something the count itself could determine.
Why Merging Needs a Linkage Criterion
The phrase two most similar clusters hides a real choice. Points have a natural similarity to one another, but a cluster is a group, so it is not immediately obvious how to say how similar a group is to another group. The source states that several linkage criteria exist, and that each one defines exactly how the similarity between two clusters is measured. The linkage criterion is therefore the rule that turns pairwise closeness into a verdict about which clusters are closest.
Stopping at a Target Cluster Count
Merging cannot go on forever, so the algorithm needs a rule for when to stop. In general terms, it merges the two most similar clusters until some stopping criterion is satisfied. In scikit-learn, the stopping criterion is the number of clusters. The user specifies a target number of clusters, and similar clusters are merged until only that number remains.
The target number of clusters does not influence which pair is merged. It only decides when the loop ends. The stopping check looks at the current state of the clusters, not at the original points, so each pass asks the same question about the arrangement that exists after the previous merge.
Tracing a Six-Point Run
Six points merged down to a target of two clusters
Six points P1 through P6 are clustered agglomeratively with a target of 2 clusters. Trace the cluster count and the merges until the stopping criterion is met. Assume that at each step the pair shown is the most similar pair under the chosen linkage criterion.
- 1Starting state
Each point is its own cluster, so there are 6 clusters. The target is 2, so the loop must continue.
- 2Merge 1
P1 and P2 are the most similar pair. They merge into one cluster, and the count drops to 5.
- 3Merge 2
P3 and P4 merge next. The count drops to 4. The count still does not equal 2, so the loop continues.
- 4Merge 3
The cluster {P1, P2} is now most similar to P5 under the criterion, so they merge. The count drops to 3, and the loop continues.
- 5Merge 4
The cluster {P3, P4} merges with P6. The count drops to 2, which equals the target, so the loop stops.
Four merges took the count from 6 to 2. The final clusters are {P1, P2, P5} and {P3, P4, P6}. The stopping check was applied after every merge, and the target only determined when the loop ended.
Mistakes Learners Make With Agglomerative Clustering
Common mistake Assuming the algorithm jumps straight to a final grouping
What it looks likeExpecting the six-point run to produce two clusters in a single step.
Why it failsThe procedure moves through a sequence of intermediate arrangements, each slightly coarser than the one before.
Do this insteadThink of the output as the end of a series of single merges, each reducing the count by exactly one.
Common mistake Believing the target count influences which clusters merge
What it looks likeReasoning that a target of 2 makes the algorithm prefer to merge the two largest groups.
Why it failsThe target only controls when the loop ends. The pair chosen at each step comes from the similarity measure between existing clusters.
Do this insteadSeparate the two questions: the linkage criterion picks the pair, and the stopping criterion decides whether to keep going.
Common mistake Treating similarity between clusters as obvious
Why it failsPoints have natural similarity to one another, but a group does not, so a rule is required to compare groups.
Do this insteadIdentify the linkage criterion that defines the similarity between the two clusters being compared.
Common mistake Comparing a point to a group that does not yet exist
Why it failsThe similarity measure is always defined between two clusters that currently exist.
Do this insteadAt each step, compare only the clusters present in the current arrangement.
Predicting the Merge Count
A dataset contains 12 points, and the target number of clusters is 3. How many merges occur before the loop stops, and how many clusters exist after the 4th merge?
Hints
- Each merge reduces the cluster count by exactly one.
- Start from 12 clusters and subtract the target count to find the number of merges required.
- After the 4th merge, subtract 4 from the starting count of 12.
Key Takeaways
- Agglomerative clustering starts with each point as its own cluster, so twenty points begin as twenty single-point clusters.
- At each step the algorithm merges the two most similar existing clusters, reducing the cluster count by exactly one per merge.
- A linkage criterion defines how the similarity between two clusters is measured, which is what decides the pair chosen at every merge.
- In scikit-learn, the stopping criterion is the number of clusters: the user sets a target, and merging continues until only that many clusters remain.