Hierarchical Clustering › Hierarchical Clustering
Machine Learning from ScratchAll chapters Hierarchical Clustering › Hierarchical ClusteringOne section · Sections in this chapter1 / 8 ↓
Reading tools Definitions & inline links
Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.
Article links
Make inline references clickable
Hierarchical clustering is a powerful unsupervised learning technique that builds a hierarchy of clusters by either merging smaller clusters into larger ones (agglomerative) or splitting larger clusters into smaller ones (divisive). Unlike k-means clustering, which requires us to specify the number of clusters beforehand, hierarchical clustering creates a complete hierarchy that allows us to examine clusters at different levels of granularity.
The key insight behind hierarchical clustering is that data points can be organized into a tree-like structure called a dendrogram, where the height of branches represents the distance between clusters. This dendrogram gives a complete picture of how data points relate to each other at different scales.
Hierarchical clustering differs from other clustering methods in several important ways. While k-means assumes spherical clusters and requires us to specify k in advance, hierarchical clustering makes no assumptions about cluster shape and provides a complete clustering solution for all possible numbers of clusters. Unlike density-based methods like DBSCAN, hierarchical clustering doesn't require tuning parameters like minimum points or epsilon radius, though it does require choosing a distance metric and linkage criterion.
The method is particularly well-suited for datasets where we expect natural hierarchical relationships, such as biological taxonomy, organizational structures, or any domain where objects naturally group into nested categories. The dendrogram visualization makes it easy to understand the clustering structure and identify natural cut points for different numbers of clusters.
Advantages
Hierarchical clustering offers several practical advantages. First, it provides a complete clustering solution for all possible numbers of clusters in a single run, eliminating the need to run the algorithm multiple times with different k values. This is particularly useful when we're uncertain about the optimal number of clusters or when we want to explore the data at multiple levels of granularity.
The dendrogram visualization is another major strength. This visual representation makes it easy to identify natural cluster boundaries and understand how clusters merge or split as we move up or down the hierarchy. The dendrogram also helps in determining the optimal number of clusters by identifying significant gaps in the merging distances.
Unlike k-means, hierarchical clustering doesn't require us to specify the number of clusters in advance, making it well-suited for exploratory data analysis. It also doesn't assume spherical clusters, allowing it to capture more complex cluster shapes. The deterministic nature of the algorithm means that given the same data and parameters, it typically produces the same results, which is valuable for reproducible research.
Disadvantages
Despite its strengths, hierarchical clustering has several limitations that can impact its practical application. The most significant drawback is its computational complexity, which is O(n³) for most implementations. This makes it computationally expensive for large datasets, often limiting its use to datasets with fewer than several thousand points. For very large datasets, the memory requirements can also become prohibitive.
The algorithm is sensitive to noise and outliers, which can significantly affect the clustering results. A single outlier can create spurious clusters or distort the entire hierarchy, making the dendrogram less interpretable. This sensitivity makes data preprocessing and outlier detection necessary before applying hierarchical clustering.
Another limitation is that hierarchical clustering doesn't perform well with clusters of very different sizes or densities. The algorithm tends to favor clusters of similar sizes, which can lead to poor results when the true clusters have dramatically different characteristics. Additionally, once a data point is assigned to a cluster, it cannot be reassigned, which can lead to suboptimal clustering if early decisions were made based on limited information.
The choice of distance metric and linkage criterion can significantly affect the results, and there's often no clear guidance on which combination works best for a particular dataset. This parameter sensitivity means that extensive experimentation may be required to find the optimal configuration, adding to the computational burden.