Hierarchical Clustering

Machine Learning
Introduced by
Ward, J. H.
Year
1963
Type
Unsupervised clustering (agglomerative)

What does it do?

Hierarchical clustering is an unsupervised method that groups observations into nested clusters and draws the result as a dendrogram, so the number of clusters need not be fixed in advance.

The Ward linkage used on this page traces to Joe H. Ward's 1963 procedure for hierarchical grouping, in which each merge is chosen to optimise an objective function.

The intuition behind the method

Imagine every observation starting out as its own tiny group. At each step the two groups that are most similar are merged, then the next two, and so on, until everything joins into a single tree. Cutting that tree at different heights gives you different numbers of clusters, so you can decide how finely to split the data after seeing the structure rather than committing to a fixed count beforehand.

History

Joe H. Ward's 1963 paper describes a procedure for hierarchical grouping in which pairs of groups are merged, one merge at a time, by choosing the union that maximises an objective function reflecting the investigator's criterion, until one group remains. The abstract motivates the approach for large-scale studies where an exact optimal solution for a given number of groups is impractical. The within-cluster sum-of-squares criterion used on this page, which measures the increase in within-group sum of squares caused by a merge, is the variance-based form now commonly used under the name Ward's linkage. The wider family of agglomerative hierarchical algorithms was surveyed by Day and Edelsbrunner, and Kaufman and Rousseeuw introduced the agglomerative (AGNES) and divisive (DIANA) procedures.

When to use it

Use hierarchical clustering for exploratory grouping when you want to see structure without fixing the number of clusters in advance. It suits numeric features where a Euclidean-type distance is meaningful, because that is the setting in which Ward's linkage, as written on this page, is defined. For ordinal or categorical features, a different linkage and distance pair is needed, and the Ward formula does not cover that case. The method has no normality requirement but depends on two analyst choices, a distance metric and a linkage method. Numeric features should be standardised before distances are computed, since features on larger scales otherwise dominate the result. Ward's 1963 procedure was motivated for large-scale studies (n > 100). With very few observations, the distance matrix and dendrogram are unlikely to show stable structure, and a partitioning method is worth comparing instead.

Limitations and considerations

  • Ward's linkage as given in the mechanics is built on squared Euclidean distances to cluster means; its merge rule is not defined for arbitrary distances, so results with other metrics come from a different criterion.
  • Merges are greedy and final: once two clusters join, the algorithm cannot separate them later, so an early merge can shape all later groupings.
  • On small samples, cluster memberships are unstable and sensitive to the linkage method.
  • Ward's criterion minimises within-cluster sum of squares and therefore favours compact, roughly spherical clusters of similar size. Elongated or unequal-sized groups may be split or merged in ways that do not match the underlying structure.
  • Outlying observations can distort the merge sequence, since an isolated point may stay unmerged until late in the tree.

Source conditions do not replace independent scientific review or validation by an analysis engine.

Strengths

  • The number of clusters does not have to be fixed in advance; it is chosen by cutting the dendrogram at a height the analyst inspects.
  • The dendrogram shows how clusters nest at successive merge heights, so you can see which groups are close and which join late.
  • No normality assumption is needed, and the procedure works from a distance matrix, so it can be applied with different distance measures, provided the linkage is matched to the distance used.
  • Every stage of the merge sequence is recorded, which lets you inspect the grouping at each level rather than only at the final partition.

Applications

  • Exploratory grouping of observations when the number of groups is not known in advance.
  • Building a dendrogram to see how cases nest at different similarity levels.
  • Generating candidate cluster counts to inform a later partitioning analysis.
  • Grouping numeric observations on a Euclidean-type distance, where Ward's linkage is defined.

How it works

How it works

1

First a distance is computed between every pair of observations using a chosen distance metric, producing a distance matrix. The metric defines what counts as 'similar', so it is a substantive choice. For numeric features, the squared Euclidean distance between observations x_i and x_j is the sum over features k of (x_ik - x_jk)^2. Ward's linkage, described below, is defined on squared Euclidean distances to cluster means, so if you use Ward's linkage the distance should be of that form; other feature types call for a different linkage with a matching distance. Because each feature enters this sum directly, features on larger scales contribute more to the distance, so numeric variables should be standardised before distances are computed.

2

Starting from each observation as its own cluster, the algorithm repeatedly merges the two clusters that are closest according to the chosen linkage method. Under Ward's criterion, the pair chosen is the one whose merge produces the smallest increase in within-cluster sum of squares, the quantity given by the formula above. Because the increase is measured in squared Euclidean distances to cluster means, this criterion tends to keep clusters compact. The linkage choice strongly shapes the final grouping.

Formula
\Delta(A,B) = \sum_{i \in A \cup B} \lVert x_i - m_{A \cup B}\rVert^2 - \sum_{i \in A}\lVert x_i - m_A\rVert^2 - \sum_{i \in B}\lVert x_i - m_B\rVert^2
3

The sequence of merges is recorded as a dendrogram, a tree whose branch heights show the distance at which clusters joined. Cutting the dendrogram at a chosen height yields the cluster assignments, so the number of clusters is read off the tree rather than specified in advance.

Common pitfalls

  • Pairing Ward's linkage with a non-Euclidean distance or with categorical features, where the merge formula does not apply.
  • Running the method on very small samples, where the distance matrix and dendrogram are not trustworthy.
  • Choosing a distance metric and linkage method without justification and reporting the dendrogram as if it were definitive.
  • Picking a cut height by convenience instead of inspecting the merge heights for natural break points.
  • Trusting cluster memberships on a small sample without rerunning with other linkage choices to see whether the assignments hold.
  • Clustering numeric features measured on different scales without standardising them first, so that the variable with the largest units dominates the distances and the merges.

Frequently asked questions

Do I need to choose the number of clusters first?

No. Hierarchical clustering builds the full merge tree regardless, and you decide the number of clusters afterward by cutting the dendrogram at a chosen height. This is one of its main differences from K-means, which requires the number of clusters in advance.

Which distance metric and linkage should I use?

Both are deliberate choices that strongly shape the result. Ward's linkage, as written on this page, is defined with squared Euclidean distances, so it fits numeric features under that distance; for other feature types, select a linkage whose definition matches your distance.

How many observations do I need?

Ward's 1963 procedure was motivated for large-scale studies with n > 100. There is no established minimum sample size for this method. With very few observations, the distance matrix and dendrogram are unlikely to show stable structure, so check the result by rerunning with other linkage choices before relying on it.

Why are my clusters unstable?

On small samples the result is sensitive to the linkage method, so memberships can shift with small changes in the data or settings. Rerun with other linkage choices to see which assignments hold. A partitioning method such as K-means or a Gaussian mixture model is worth comparing, though it is not a guaranteed fix.

Related methods

Sources

  1. Ward, J. H. (1963). Hierarchical Grouping to Optimize an Objective Function. Journal of the American Statistical Association, 58(301), 236–244.

    Open DOI reference