hierarchical clustering
/ hy-uh-RAR-kik-ul KLUS-ter-ing /
Hierarchical clustering groups data not into a flat set of bins but into a nested family tree, like the way biologists organize life into species inside genera inside families. The most common version, agglomerative, starts at the bottom: every single data point is its own tiny cluster. Then it repeatedly fuses the two closest clusters into one, and again, and again — small clumps merging into bigger ones — until everything has joined a single grand cluster at the top. The whole history of merges is the result.
That history is drawn as a tree called a dendrogram, which looks like a tournament bracket turned on its side: points that joined early sit on short, low branches because they were very similar, while groups that only merged near the top are joined by tall branches because they were quite different. The beauty is that you don't have to commit to a number of clusters up front the way k-means forces you to. Instead you draw a horizontal line across the tree at whatever height you like, and however many branches it crosses is how many clusters you get. Cut low for many fine groups, high for a few broad ones.
It's intuitive, gives you that whole multi-level picture at once, and demands no guess at k beforehand — which is why it's a staple in biology and genetics for building family trees of organisms or genes. The catch is cost: comparing every cluster to every other at each step is slow and memory-hungry, so it doesn't scale to very large datasets. You also have to choose how to measure the distance between two clusters (nearest pair? farthest pair? average?), and that choice can quietly reshape the whole tree.
Cluster five animals by their traits. Cat and lion fuse first (both feline). Dog joins them next, forming a carnivore branch. Sparrow and eagle pair off separately as birds. The dendrogram shows it all; slice the tree low and you get four groups, slice it high and you get just two: mammals and birds.
The dendrogram lets you pick your number of clusters after the fact, just by where you cut.
Unlike k-means, you don't fix the number of clusters up front — you read it off the tree by choosing where to cut. The trade-off is speed: pairwise merging is expensive, so it's best suited to small-to-medium datasets.