Skip to content

ML Models & Algorithms

Hierarchical Clustering

In shortClustering that builds a tree of nested groups by repeatedly merging or splitting clusters, shown as a dendrogram you can cut at any level.

Updated 24 Oct 2026· 2 min read

Hierarchical clustering groups data into a tree of nested clusters instead of a single flat set. Small, very similar groups sit inside larger, looser ones, and the whole structure can be drawn as a dendrogram. You choose how many clusters you want afterwards by cutting the tree at a particular height, which makes it a natural fit for taxonomies and topic hierarchies.

How it works

There are two directions:

  • Agglomerative (bottom-up). Every item starts as its own cluster, and the two closest clusters are merged again and again until one remains. This is the version most libraries use.
  • Divisive (top-down). Everything starts in one cluster, which is split recursively.

A linkage rule decides how the distance between two groups is measured: single linkage uses the closest pair of points, complete linkage the farthest, average linkage the mean, and Ward’s method merges whichever pair increases within-cluster variance least. The height of each join in the dendrogram shows how far apart the groups were when they merged.

How it’s used in SEO and marketing

  • Keyword clustering by SERP overlap. MLforSEO’s SERP automation guide builds an average-linkage hierarchy from the number of shared ranking URLs, so you can see near-misses as well as clear clusters.
  • Site taxonomy. Nested topic groups map naturally onto categories and subcategories.
  • Customer segmentation. The segmentation practical uses it to find macro segments that split into useful micro segments, such as high-value customers who buy often in small amounts versus rarely in large ones.
  • Competitor grouping. Cluster domains by their metrics to see who competes most directly.

Example

You collect the top 10 URLs for 200 keywords and count, for every pair, how many URLs they share. Feeding that into agglomerative clustering gives a dendrogram. Cutting at “three or more shared URLs” groups keywords Google treats as the same topic, so they can share one page; keywords that only join higher up the tree are related but probably need separate pages.

Limitations and things to watch

  • It gets slow and memory-hungry on large datasets because it compares every pair. MLforSEO’s segmentation lesson suggests K-means instead for tens of thousands of customers or more.
  • Merges are final: a poor early merge cannot be undone.
  • Results depend heavily on the linkage rule and distance measure.
  • At any single cut, each item belongs to one cluster, so it behaves as hard clustering.

Learn it on MLforSEO

Where Hierarchical Clustering shows up on MLforSEO

Sources and further reading

Other terms from ML Models & Algorithms

See all 55 ML Models & Algorithms terms →