Skip to content
tezvyn:
Menu

Hierarchical Clustering: Building a Family Tree for Data

Source: Wikipedia: Hierarchical clusteringMediumHow cards are made

Hierarchical clustering builds a family tree of your data, not just a single set of groups. It's used when you don't know the number of clusters beforehand, like in biology or market segmentation. The main footgun: early merges are final and can't be undone.

Why it exists

Many clustering algorithms, like K-Means, force you to decide the number of clusters ('k') before you start. Hierarchical clustering was developed to solve this problem by building a full hierarchy of clusters, from individual points up to one single group, allowing you to choose the number of clusters after analyzing the structure.

The mental model

Think of it as creating a family tree for your data points. You can either start with individuals and group them into families, then clans, then tribes (a 'bottom-up' or agglomerative approach), or you can start with the entire population and divide it into continents, then countries, then cities (a 'top-down' or divisive approach). The final output is a tree diagram called a dendrogram, which shows how the clusters are related at every level.

How it works

There are two main strategies. The most common is Agglomerative (bottom-up): first, every data point starts as its own cluster. Second, the algorithm finds the two most similar clusters and merges them. Third, this process repeats until only one cluster, containing all data points, remains. The history of these merges forms the hierarchy. The less common Divisive (top-down) method does the reverse: it starts with all data in one cluster and recursively performs splits.

When to use it

Use hierarchical clustering when you don't know the optimal number of clusters beforehand. Its visual output, the dendrogram, is excellent for data exploration and understanding nested relationships. This makes it a staple in fields like bioinformatics for creating phylogenetic trees and in social sciences for analyzing social structures.

When not to use it

Its primary weakness is its greedy nature. Once a merge or split is made, it's irreversible. A poor choice early on can lead to a suboptimal final structure. It is also computationally intensive, often scaling poorly to large datasets compared to algorithms like K-Means. Don't use it on massive datasets where performance is critical.

One canonical example

Agglomerative clustering is the classic implementation. Imagine five customer data points. The algorithm first merges the two closest points, say Customer A and Customer B, into one cluster. Now there are four clusters. It then finds the next closest pair, which might be Customer D and Customer E. Now there are three clusters. This continues until all customers are in one large group, with the dendrogram showing the exact sequence and distance of each merge.

Interview question

What is a fundamental methodological limitation of hierarchical clustering?

  • a.It cannot effectively visualize the relationships between different clusters.
  • b.Decisions made early in the clustering process, such as merging or splitting, are irreversible.Correct
  • c.It requires the user to predefine the desired number of clusters (k) before execution.
  • d.It is inherently designed for small datasets and cannot be applied to large-scale data.
Why?

The card explicitly states that "early merges are final and can't be undone" and "Once a merge or split is made, it's irreversible," highlighting this as its primary weakness. While it scales poorly to large datasets (option D), the irreversibility of decisions is a core methodological limitation, not just a performance characteristic.

Just read this? Test yourself on what you have been reading.

Read the original → en.wikipedia.org

Put your scrolling time to good use

Learn one idea, try a quiz and save useful cards for revision. Tezvyn makes it easy to learn and stay current in your tech field, a few minutes at a time.

The iPhone app is on the way

We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.

Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.

Get it on Google PlayiPhone app coming soon

We are hiring for this. Open roles that interview on data science — each one lists the topics its interview covers.

See open roles