Concepts / Clustering Fundamentals

Clustering Fundamentals

Agglomerative clustering is a family of algorithms that starts with each point as its own cluster.

  • Programming

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?

  • 1

  • 20

  • 0

Reveal answer
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.

Cluster {A}one pointCluster {A, B}two pointsCluster {B}one pointCluster {C}one pointCluster {C}one pointCluster {D, E}two pointsCluster {D}one pointCluster {E}one point
Before any merging, each of the five points sits in its own cluster. After two merges, points A and B share one cluster and points D and E share another, while point C remains alone. The number of clusters has dropped from five to three.

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.

Start: 5 clustersA, B, C, D, E each aloneAfter merge 1: 4clustersA and B combinedAfter merge 2: 3clustersD and E combinedAfter merge 3: 2clusters{A, B} joins Cmerge A and Bmerge D and Emerge {A, B} with C
Each arrow is one pass through the merge step. The cluster count drops by exactly one per merge, and the cluster contents change with each pass. The example starts from five single-point clusters.

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.

Cluster {A, B}two pointsCluster {C}one pointCluster {C}one pointCluster {D, E}two points
Two different pairs of existing clusters are available at the same moment. The linkage criterion determines which pair is considered the most similar, so the choice of criterion decides which merge happens next.

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.

Start: one clusterper pointFind two most similarclustersjudged by linkage criterionMerge themcount drops by oneCluster count equalstarget?checked on current clustersReturn currentclustersbegin loopnoyes
The loop finds the most similar pair, merges it, and then checks the current cluster count against the target. It returns to the search until the count equals the target, and only then stops.

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

Worked example

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.

  1. 1
    Starting state

    Each point is its own cluster, so there are 6 clusters. The target is 2, so the loop must continue.

  2. 2
    Merge 1

    P1 and P2 are the most similar pair. They merge into one cluster, and the count drops to 5.

  3. 3
    Merge 2

    P3 and P4 merge next. The count drops to 4. The count still does not equal 2, so the loop continues.

  4. 4
    Merge 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.

  5. 5
    Merge 4

    The cluster {P3, P4} merges with P6. The count drops to 2, which equals the target, so the loop stops.

Result

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 like

    Expecting the six-point run to produce two clusters in a single step.

    Why it fails

    The procedure moves through a sequence of intermediate arrangements, each slightly coarser than the one before.

    Do this instead

    Think 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 like

    Reasoning that a target of 2 makes the algorithm prefer to merge the two largest groups.

    Why it fails

    The target only controls when the loop ends. The pair chosen at each step comes from the similarity measure between existing clusters.

    Do this instead

    Separate 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 fails

    Points have natural similarity to one another, but a group does not, so a rule is required to compare groups.

    Do this instead

    Identify 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 fails

    The similarity measure is always defined between two clusters that currently exist.

    Do this instead

    At each step, compare only the clusters present in the current arrangement.

Predicting the Merge Count

EASY

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.

Related concepts

More concepts starting with C