Concepts / Linkage Criteria in Hierarchical Clustering

Linkage Criteria in Hierarchical Clustering

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

  • Programming

Starting From Individual Points

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?

If there is no group yet, what would be a reasonable first arrangement of the data before any merging happens?

Reveal answer
Answer:

Every point starts as its own cluster, so each cluster contains exactly one point.

This is the defining starting state of agglomerative clustering. Grouping only begins after this arrangement is in place, and the answer is built into the first sentence of the definition.

Tracing the Merge Loop

Every algorithm in the agglomerative family begins the same way: each point is declared to be its own cluster. If there are twenty data points, the algorithm starts with twenty clusters, each containing exactly one point. Nothing has been grouped yet.

From that starting arrangement, the algorithm repeats one operation. It finds the two most similar clusters that currently exist and merges them into a single cluster. Because a merge always reduces the number of clusters by exactly one, the count shrinks step by step. The procedure does not jump straight to a final answer. It moves through a sequence of intermediate arrangements, each one slightly coarser than the one before.

5 clustersA, B, C, D, E alone4 clustersAB, C, D, E3 clustersAB, CD, E2 clustersABE, CDmerge most similar pairmerge most similar pairmerge most similar pair
How does the number of clusters change step by step, from every point starting alone to the merges that follow? This illustration uses five illustrative points A to E with a target of two clusters.

Notice in this trace that the cluster count is the only thing the diagram tracks. Each step removes exactly one cluster, and the arrangement grows coarser as it goes. The diagram does not yet say which two clusters were chosen at each step. That decision is a separate question, and it is where linkage criteria come in.

Why Cluster Similarity Needs a Definition

The phrase 'two most similar clusters' hides a real choice. Points have a natural similarity to one another, but a cluster is a group, and it is not immediately obvious how to say how similar one group is to another group. Once a cluster contains several points, the question changes from how close two points are to how close two groups of points are.

Definition

A linkage criterion is the rule that specifies how the similarity between two clusters is measured. Several linkage criteria exist, and each one defines what 'most similar cluster' means in the merge step.

Point-to-point distance alone is not enough. A single distance value between two individual points does not tell the algorithm how to compare a cluster holding three points with a cluster holding two. Without a rule for cluster-to-cluster similarity, the algorithm would have no defined way to pick the next merge once merging has begun.

When Merging Stops in scikit-learn

Merging cannot go on forever, so the algorithm needs a rule for when to stop. In general terms, the algorithm merges the two most similar clusters until some stopping criterion is satisfied. The source specifies the stopping criterion implemented in scikit-learn: the number of clusters. The user specifies a target number of clusters, and similar clusters are merged until only that number of clusters remains.

Every point is aclusterstarting stateCount equals target?compare current count totargetMerge two mostsimilar clusterschosen by linkage criterionStop mergingtarget number reachedcheck current stateno, still too manyrecheck new countyes
At each iteration, what check decides whether to keep merging or stop, and which path does the algorithm take? The check compares the current cluster count with the target number of clusters.

Read the loop as a cycle with an exit. The algorithm keeps returning to the search for the most similar pair until the cluster count matches the stopping condition, and only then does it stop. The stopping condition is checked against the current state of the clusters, not against the original points.

Mistakes Beginners Make

  • Common mistake

    Assuming the algorithm starts with a set number of groups

    What it looks like

    Believing that clustering begins with three groups because the target is three.

    Why it fails

    The source states that every point starts as its own cluster, so the count starts at the number of points.

    Do this instead

    Begin by counting the points. Each point is one cluster before any merge happens.

  • Common mistake

    Thinking a merge can remove more than one cluster at a time

    What it looks like

    Expecting a step to take five clusters straight to two.

    Why it fails

    A merge always reduces the number of clusters by exactly one.

    Do this instead

    Count one fewer cluster after each merge and repeat until the target is reached.

  • Common mistake

    Treating the target number as the rule that picks which clusters merge

    Why it fails

    The target only decides when merging ends. Which pair merges is decided by the linkage criterion.

    Do this instead

    Keep the two questions separate: the linkage criterion picks the pair, and the stopping criterion decides when to stop.

  • Common mistake

    Comparing a point to a group instead of comparing two existing clusters

    Why it fails

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

    Do this instead

    At each merge, identify the specific pair of current clusters being compared.

Practice Tracing Merges

EASY

You start with 8 data points and set the target number of clusters to 3. Each merge reduces the cluster count by one. How many merges happen before the algorithm stops, and what is the cluster count right after the last merge?

Hints
  • Start by writing down the cluster count before any merge. Each point is its own cluster.
  • Each merge removes exactly one cluster. Count how many steps it takes to go from 8 down to 3.

Key Takeaways

  • Agglomerative clustering starts with every point as its own cluster, so the cluster count begins at the number of points.
  • At each step the algorithm merges the two most similar existing clusters, reducing the cluster count by exactly one.
  • A linkage criterion defines how the similarity between two clusters is measured, because a single point-to-point distance does not settle how to compare groups.
  • In scikit-learn, the stopping criterion is the number of clusters: merging continues until the user-specified number of clusters remains.
  • The linkage criterion decides which pair merges at each step, while the stopping criterion only decides when the loop ends.

Related concepts

More concepts starting with L