Dendrogram
A dendrogram is a tree-like diagram that records the sequence of merges (or splits) performed by a hierarchical clustering algorithm. It's one of the most intuitive ways to visualize how clusters form step by step.
How to Read a Dendrogram
- Each leaf at the bottom represents a single data point.
- Each merge point (called a "node") shows two clusters being combined.
- The height of a merge represents the distance (or dissimilarity) between the two clusters being joined.
Plotting a Dendrogram in Python
from scipy.cluster.hierarchy import dendrogram, linkage
import matplotlib.pyplot as plt
Z = linkage(data, method="ward")
dendrogram(Z)
plt.title("Dendrogram")
plt.xlabel("Data Points")
plt.ylabel("Distance")
plt.show()
Choosing the Number of Clusters
One of the most useful things a dendrogram tells you is how many clusters to pick. By drawing a horizontal line across the tallest vertical lines that aren't crossed by any merge, you can count how many clusters that cut produces.
Coming Up Next
With clustering covered, the course now shifts to another major unsupervised learning theme - reducing the number of features in your data through Dimensionality Reduction.