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.

Not startedJump to quiz

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 .

PointDistance to Distance to Assign
0
50

So and . The update step comes next (6.3).

123412345P1P2P3P43.611.41
P3 is 1.41 from μ₂ but 3.61 from μ₁, so it joins cluster 2. Crosses show where the centroids move after the update step.

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

Euclidean ; Manhattan . K-means compares squared Euclidean.

Unscaled features

The largest-range feature dominates distances. Standardise before K-means, K-NN, SVM.

See every cheatsheet by category →

Check your understanding

Score 75% or more to master this lesson and earn XP. Answer first, then check.

Q1calculateWhat is the Euclidean distance between and ?
Q2calculateCentroids are and . Which cluster does the point join?
Q3calculateWhat is the Manhattan distance between and ?
Q4diagnoseA retailer clusters customers on annual income (£20k–£200k) and store visits (1–40), unscaled. The clusters split purely by income. Why?
Q5conceptWhy can K-means compare squared distances instead of distances when assigning points?