Distance Metrics for Hierarchical Clustering
What You'll Learn
You'll learn how to choose the right distance metric for hierarchical clustering based on your data's unique characteristics.
The Core Idea
Just like linkage criteria (which you learned in lessons 357-358) determine how clusters merge, distance metrics determine how far apart two data points are. The distance metric you choose fundamentally affects which points get grouped together.
Think of it like measuring how "different" two cities are. You could use:
- Straight-line distance (as the crow flies)
- Manhattan distance (walking along city blocks)
- Similarity in character (comparing culture, climate, size)
Each measurement tells a different story!
Three Common Distance Metrics
Euclidean Distance
The straight-line distance between points. Best for data where magnitude matters and features are on similar scales.
Example: Clustering customers by age and income (after scaling).
Manhattan Distance
Sum of absolute differences along each dimension. Works well with high-dimensional data and is less sensitive to outliers.
Example: Clustering products by discrete ratings across categories.
Cosine Distance
Measures the angle between vectors, ignoring magnitude. Perfect when direction matters more than size.
Example: Clustering documents by topic (word frequencies can vary wildly, but topic similarity is about proportions).
Choosing the Right Metric
- Euclidean: Default choice for continuous, scaled data with meaningful magnitudes
- Manhattan: High dimensions, presence of outliers, or grid-like structures
- Cosine: Text data, sparse features, or when scale doesn't matter (only proportions do)
Key Takeaway: The distance metric shapes what "similar" means in your clustering—Euclidean for magnitude-sensitive relationships, Manhattan for robust city-block distances, and cosine for directional similarity regardless of scale.