Lesson 6.2 · 8 min read · about 50 min to master at a very slow pace
Distance Calculations and Cluster Assignment
Euclidean and Manhattan distance, how to assign points to centroids by hand, a fully worked 2-D example, and why unscaled features let one variable dominate the clusters.
Measuring distance
Distances between and in dimensions
K-means uses (squared) Euclidean distance. For assignment, comparing squared distances gives the same answer as comparing distances, and skips the square root.
Quick check
, : Euclidean ; squared ; Manhattan .
Worked example: one assignment step
Points , , , ; ; initial centroids and .
| Point | Distance to | Distance to | Assign |
|---|---|---|---|
| 0 | |||
| 5 | 0 |
So and . The update step comes next (6.3).
Scale matters
Distance adds up squared differences across features, so a feature with a large numerical range dominates. Cluster customers on annual income (£20,000–£200,000) and store visits (1–40), and the clusters will split purely by income: a £1,000 income difference outweighs a 30-visit difference.
Fix
Standardise features (mean 0, SD 1) before K-means, unless the raw units are genuinely comparable. The same applies to K-NN and SVMs.
Categories
Means and Euclidean distance are undefined for categorical data ("red", "green"). Use variants such as k-modes or a suitable distance.
Cheatsheet
Distances
Unscaled features
Check your understanding
Score 75% or more to master this lesson and earn XP. Answer first, then check.