Skip to content
AI.info

Unsupervised learning

Linkage Choices, Connectivity, and Tree Cuts

Compare single, complete, average, and Ward linkage, add connectivity constraints, and choose defensible cuts.

By the end you can

Analogy

Merging islands by bridges, borders, or total travel

Three planners group the same islands. One merges them when any two shores are close, another considers the farthest points, and a third averages all travel distances. Ward linkage has no counterpart in travel at all, since it merges whichever pair keeps variance in feature space lowest.

The planners are not running different programs. In 1967 Lance and Williams reduced the conventional strategies to a single linear recurrence controlled by four parameters. Between the first planner and the second, only the sign of one coefficient changes: γ = −0.5 becomes γ = +0.5. Different definitions of group proximity still produce different archipelagos. The definition is four numbers long.

The tree changes when the meaning of “closest groups” changes.

Comparison

Four biases hidden inside common linkages

These are not defects in isolation. They are consequences of the structure each method rewards. For single linkage the consequence has a proof attached.

The elongated shapes single linkage recovers and the chaining it suffers are one fact, not two. Gower and Ross established that in 1969: “Minimum spanning trees (MST) and single linkage cluster analysis (SLCA) are explained and it is shown that all the information required for the SLCA of a set of points is contained in their MST.” If the analysis is the minimum spanning tree, one accidental short edge is enough. The bridge joins two otherwise separate basins because there is nothing else in the tree to weigh against it. Daniel Müllner restates the observation and builds an MST-based single-linkage algorithm on it.

Cost is the other reason single linkage survives its worst property. Sibson's SLINK, published in 1973, reports that “The algorithm achieves the theoretical order-of-magnitude bounds for both compactness of storage and speed of operation”. That made single-link analysis feasible for numbers of operational taxonomic units well into the 10^3-10^4 range. Müllner records that SLINK needs “no working copy of the Θ(N2) input array and only Θ(N) working memory”. Murtagh and Contreras note that the O(n^2) implementations for single link and a non-unique complete link — Sibson (1973), Rohlf (1973), Defays (1977) — “have been widely cited”. The memory advantage is real. A time advantage is not: SciPy v1.18.0 documents O(n^2) for 'single' via the minimum spanning tree, and equally O(n^2) for 'complete', 'average', 'weighted' and 'ward' via the nearest-neighbour chain algorithm. O(n^3) is reserved for the remaining methods.

And a widely cited implementation is not automatically the method its name claims. Müllner warns that Defays (1977), “mostly cited as a fast algorithm for complete linkage clustering”, “definitely is not an algorithm for complete linkage clustering, as the complete linkage method is commonly defined”. That is the second linkage in this lesson whose label in software outruns its arithmetic. The first is Ward.

FigureComparison · 4 columns

Single linkage

Preserves connectivity through nearest cross-cluster points.

  • Can recover elongated shapes
  • Suffers from chaining through bridges
  • Is sensitive to accidental links
  • Needs careful graph or distance design

Complete linkage

Controls the worst pairwise separation within a merge.

  • Favors compact bounded groups
  • Can split elongated structure
  • React strongly to extreme points
  • Creates relatively tight diameters

Average linkage

Balances all cross-cluster pairwise distances.

  • Moderates single and complete behavior
  • Can be computationally demanding
  • Still depends heavily on metric
  • May smooth meaningful local structure

Ward linkage

Minimizes the variance increase from each merge.

  • Pairs naturally with Euclidean geometry
  • Often creates compact balanced groups
  • Is affected by feature scaling
  • Should not be used with arbitrary dissimilarities

One dataset, four incompatible trees

In R the entire choice is one string argument. The stats::hclust manual page lists eight values for method: "ward.D", "ward.D2", "single", "complete", "average" (= UPGMA), "mcquitty" (= WPGMA), "median" (= WPGMC) and "centroid" (= UPGMC). SciPy's scipy.cluster.hierarchy.linkage documents its own formal definitions of the same rules — single as Nearest Point, complete as Farthest Point, average as UPGMA, and the Ward update.

Nothing in either interface touches the data. The argument changes what "closest" means, and the hierarchy changes with it. Single linkage produces one winding chain. Complete linkage breaks the same points into compact pieces. Ward returns balanced groups. No implementation bug is required. Each rule asks a different question about distance between groups, and therefore builds a different tree from one distance matrix.

Linkage is the clustering objective expressed through merge decisions.

Visual

How linkage defines the next merge

The algorithm repeatedly selects the pair of clusters with the smallest linkage value. The rules that supply that value are not separate algorithms. Lance and Williams settled the point in 1967: “The conventional strategies are shown to be simple variants of a single linear system defined by four parameters.”

The system gives the distance from a newly merged cluster i∪j to any remaining cluster k:

d(i∪j,k) = α_i d(i,k) + α_j d(j,k) + β d(i,j) + γ |d(i,k) − d(j,k)|

Single linkage is α_i = α_j = 0.5, β = 0, γ = −0.5. Complete linkage is identical except γ = +0.5 — one sign, and the nearest cross-cluster pair becomes the farthest. Group average (UPGMA) is α_i = |i|/(|i|+|j|), β = 0, γ = 0.

Ward is not one of the strategies Lance and Williams parameterised; their 1967 paper does not consider it. Wishart brought Ward's criterion into the same framework in 1969, with α_i = (|i|+|k|)/(|i|+|j|+|k|), β = −|k|/(|i|+|j|+|k|), γ = 0, applied to squared Euclidean distances. It is the only one of the four whose coefficients depend on the size of the third cluster k. Murtagh and Contreras print the same table, “Specifications of seven hierarchical clustering methods”, covering single link, complete link, group average (UPGMA), McQuitty, median, centroid and Ward's method.

FigureHierarchy · 4 levels
  • Single linkage

    Uses the closest pair of points across two clusters.

    • Complete linkage

      Uses the farthest cross-cluster pair.

      • Average linkage

        Uses the average pairwise distance across clusters.

        • Ward linkage

          Chooses the merge that causes the smallest increase in within-cluster variance.

Four linkages, one recurrence: single and complete differ by the sign of γ alone.

Key idea

Ward linkage is not a universal option for any distance matrix

Ward's criterion relies on changes in squared Euclidean variance around means. The two most widely used implementations do not leave that to the reader's judgement.

SciPy states it as item 2 of the numbered list under the Notes rubric of scipy.cluster.hierarchy.linkage, in v1.18.0: “Methods 'centroid', 'median', and 'ward' are correctly defined only if Euclidean pairwise metric is used.” SciPy documents the restriction and lets the call run. scikit-learn 1.9.0 refuses instead. The metric parameter of sklearn.cluster.AgglomerativeClustering reads “If linkage is "ward", only "euclidean" and "l2" are accepted.”, and the restriction is enforced at fit time.

Two independent libraries, the same constraint, written once as a documented caution and once as a rejected argument. Use a linkage compatible with the available geometry. If the data requires a specialized relation, validate average or graph-constrained alternatives instead of forcing Ward.

A named linkage carries mathematical assumptions — here, ones two libraries have written into their APIs.

Steps

Select linkage and cut as one validation problem

The final partition depends both on how the tree was built and on the level chosen. Step 3 is where the hidden trade-off sits.

A connectivity constraint does not merely narrow the search. It changes which linkage rules remain usable. scikit-learn ran its own example on 1500-sample Swiss-roll and 2D-spiral data, with kneighbors_graph at n_neighbors=10 and 30, and records the cost: “Second, when using a connectivity matrix, single, average and complete linkage are unstable and tend to create a few clusters that grow very quickly.” The same page names the mechanism — “having a very small number of neighbors in the graph, imposes a geometry that is close to that of single linkage”. The graph deletes the long-distance comparisons by which average and complete linkage normally resist chaining. The smaller the k, the more they percolate.

For Ward the complementary result runs the other way. A 2021 review of hierarchical agglomerative clustering with and without contiguity constraints reports: “Finally, a simulation study shows that the constrained version of HAC can sometimes provide more relevant results than its unconstrained version despite the fact that the constraint leads to optimize the objective criterion on a reduced set of solutions at each step.”

So a constraint is neither free nor merely restrictive. It buys speed, it can beat the unconstrained fit, and it degrades three of the four linkages toward single-linkage percolation at the same time. That is a design decision to be argued for at step 3, not a default.

FigureProcess · 5 steps
  1. 1. State desired shape

    Write whether chains, compact diameters, average cohesion, or variance control matters.

  2. 2. Fit plausible linkages

    Build several trees under the same preprocessing and distance.

  3. 3. Add structural constraints

    Use spatial, temporal, or graph connectivity only when those restrictions are legitimate.

  4. 4. Compare candidate cuts

    Inspect sizes, exemplars, stability, merge gaps, and intended actions.

  5. 5. Preserve the hierarchy

    Store parent-child relationships even when one operational cut is selected.

Example

Choosing linkage by the structure you are willing to assume

Examples make the merge criterion easier to connect with actual data. Each one below is the coefficient behaviour showing through a domain.

  • River networks: single linkage may preserve a winding connected corridor. But all the information the analysis requires sits in the minimum spanning tree (Gower and Ross, 1969), so one erroneous bridge edge merges two separate basins.
  • Quality-control batches: complete linkage can isolate tight process regimes when the maximum within-group spread matters — the same recurrence as single linkage, with γ = +0.5 instead of γ = −0.5 (Lance and Williams, 1967).
  • Document families: average linkage (UPGMA, α_i = |i|/(|i|+|j|), β = 0, γ = 0) can reduce the effect of one unusually similar pair across otherwise different topics, and SciPy v1.18.0 documents it at O(n^2), the same order as 'complete' and 'ward'.
  • Customer profiles: Ward may create interpretable compact groups after scaling, but scikit-learn 1.9.0 will accept only "euclidean" or "l2" for the metric, and the method can still divide a continuous gradient into artificial bands.
  • Image superpixels: a spatial connectivity graph can forbid merges between visually similar regions that are not adjacent in the image, and by scikit-learn's own account it will also make single, average and complete linkage unstable, growing a few clusters very quickly.

The cut cannot rescue a badly matched linkage

Analysts often tune the dendrogram height while leaving the merge criterion unquestioned. The tree has already encoded which shapes and bridges are acceptable.

Nor is judging the gap by eye the only alternative to a rule. The rules disagree with each other, and that disagreement has been measured. Milligan and Cooper reported it in 1985: “A Monte Carlo evaluation of 30 procedures for determining the number of clusters was conducted on artificial data sets which contained either 2, 3, 4, or 5 distinct nonoverlapping clusters.” Four hierarchical clustering methods analysed the data. The outcome was not a winner but a spread: “The simulation results for the stopping rules revealed a wide range in their ability to determine the correct number of clusters in the data.” Several worked fairly well. Others performed rather poorly. Nearly thirty years later the NbClust R package was built around the same set — “Indeed, Milligan and Cooper (1985) examined thirty indices, with simulated data, where the number of clusters is known beforehand” — and provided 30 indices. Only thirteen were then available in R, and some of the indices from that study still could not be reimplemented.

Treat linkage, metric, connectivity, and cut as a joint design. Ward published the criterion in 1963, where the procedure “is suggested for use in large-scale (n > 100) studies when a precise optimal solution for a specified number of groups is not practical”, reducing n sets to n − 1 “by considering the union of all possible n(n − 1)/2 pairs and selecting a union having a maximal value for the functional relation, or objective function”. It was proposed as an approximation from the start. A defensible hierarchy explains why the four choices match the intended structure. It does not ask the cut to repair the first three.

Thirty published stopping rules, measured head to head, ranged from fairly good to rather poor.

Case

Two algorithms in the software, both called Ward

Two algorithms in circulation both claim to be Ward's method. Murtagh and Legendre asked which one actually implements it. Their answer, published in 2014: “Two algorithms, Ward1 and Ward2, are found in the literature and software, both announcing that they implement the Ward (1963) clustering method”, and applied to the same distance matrix “they produce different results”. Only one is the method — “only Ward2 minimizes the Ward clustering criterion and produces the Ward method”. Ward1 reaches the same criterion only when it is fed squared distances.

R documents the consequence in its own manual rather than leaving it to the literature. The stats::hclust Details section states that “Two different algorithms are found in the literature for Ward clustering.” Option "ward.D" does not implement the clustering criterion of Ward Jr. (1963); "ward.D2" does, with the dissimilarities squared before cluster updating. The page cites Murtagh and Legendre (2014) for this. "ward.D" was the only "ward" option in R versions up to 3.0.3, and agnes(*, method="ward") corresponds to hclust(*, "ward.D2").

The two names in the method list are therefore not a stylistic choice. They are the software stating, in its own reference manual, that one of its two Ward options is not Ward.

Key takeaways