Hierarchical Clustering: Building a Family Tree for Data
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.
Read the original → en.wikipedia.org
Get five bites like this every day.
Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.