Distance measures how far apart two observations are under a chosen rule. In clustering, that rule helps determine which observations appear similar: for centroid-based clustering, a smaller distance to a cluster centroid means greater similarity. Choosing a different distance measure—or different attributes—can change the resulting groups, so start with the business question and the variables that matter to it. section 2.3 section 2.2
Common ways to measure distance between points include:
- Euclidean distance: the straight-line distance. For points (x1, y1) and (x2, y2), calculate √((x2 − x1)² + (y2 − y1)²). section 2.3
- Manhattan distance: movement along perpendicular grid axes, calculated as |x2 − x1| + |y2 − y1|. section 2.3
- Chebyshev distance: the largest absolute difference along any coordinate dimension. section 2.3
Figure 2.5 Euclidean distance, Chebyshev distance, Manhattan distance, and cosine distance are the primary distance metrics used. Note how the distance is different for two points using these metrics. In Euclidean distance, the direct distance is measured between two points, as shown by the first figure on the left.
Compare the paths and measurements for the same two points. The picture makes clear why changing the distance rule can change a clustering result. section 2.3
In hierarchical clustering, keep the point-to-point distance measure separate from the linkage rule that turns point distances into a distance between clusters. Single linkage uses the closest pair across clusters; complete linkage uses the farthest pair; average linkage averages all cross-cluster pairs. Ward linkage instead aims to minimize variability in the merged cluster. Changing the linkage rule can change which clusters merge. section 2.4.2
Try a hierarchical clustering cut
With prepared data in X_standard, run scipy.cluster.hierarchy.linkage(X_standard, 'average', metric='euclidean'), then plot its dendrogram. Try complete and Ward linkage to compare the merges. A separate distance cutoff passed to fcluster(..., criterion='distance') determines the final groups; it is not the same choice as metric='euclidean'. Plot the assigned clusters and vary the cutoff: different values can produce different numbers of clusters. section 2.4.5
There is no one distance choice for every dataset. Euclidean distance is often used, but the attributes, distance measure, linkage rule, and cutoff should be checked against the intended interpretation of the clusters. Distance also matters in DBSCAN, where a radius and the distances to nearby points help determine neighborhoods; its results are sensitive to the chosen settings. section 2.7 section 2.5.2









