Hierarchical Clustering › Visualizing Hierarchical Clustering

Michael BrenndoerferAugust 14, 20254 min read
Machine Learning from ScratchAll chapters
Part 7 of 9Unsupervised Learning
Chapter 54Hierarchical Clustering › Visualizing Hierarchical Clustering
Reading section 3 of 8 · Visualizing Hierarchical Clustering · 4 minSection 3 of 8 · 4 min

Book contents

Section 3 of 8 · 4 min read

Hierarchical Clustering › Visualizing Hierarchical ClusteringOne section · Sections in this chapter3 / 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

Let's create visualizations that demonstrate the key concepts of hierarchical clustering, including how different linkage criteria affect the clustering results and how dendrograms reveal the hierarchical structure.

Out[2]:
Visualization
Scatter plot showing original dataset with three clusters.
Original dataset with three distinct clusters used for hierarchical clustering demonstration. The data points are standardized to ensure equal influence from both features. This ground truth visualization helps us understand the natural grouping structure that hierarchical clustering should ideally discover. The three clusters are well-separated.
Single linkage dendrogram visualization.
Single linkage dendrogram showing the hierarchical clustering structure. Single linkage tends to create elongated, chain-like clusters because it only requires one pair of points to be close for clusters to be considered similar. The dendrogram reflects this permissive behavior: many merges happen at relatively low distances, and larger jumps appear only when these connected chains are joined.
Complete linkage dendrogram visualization.
Complete linkage dendrogram showing more compact clustering behavior. Complete linkage creates spherical, tightly-knit clusters because all points in the resulting cluster must be relatively close to each other. Because it uses the farthest pair of points between clusters, its merge heights can be larger than single linkage even when the resulting clusters are more compact.
Average linkage dendrogram visualization.
Average linkage dendrogram and gives a balanced approach between single and complete linkage. Average linkage considers all pairwise distances between clusters. The dendrogram shows intermediate merge heights, indicating clusters of moderate compactness that often better reflect the natural structure of real-world data.

The visualization above shows several key concepts in hierarchical clustering. The top-left plot shows our original data with three distinct clusters, which is our ground truth. The three dendrograms below show how different linkage criteria create different hierarchical structures.

Notice how the single linkage dendrogram (top-right) merges many points at low distances because one close pair is enough to connect two clusters. The complete linkage dendrogram (bottom-left) uses a stricter farthest-point criterion, so its merge heights are often larger even though the resulting clusters are more compact. The average linkage dendrogram (bottom-right) provides a balanced approach between these two extremes.

The height of the horizontal lines in each dendrogram represents the distance at which clusters were merged. Longer lines indicate that clusters were merged at greater distances, suggesting they were less similar. We can use significant gaps in the merging distances to choose the number of clusters.