Why should you standardise features before running k-nearest neighbours (k-NN)?

Supervised learning, Nearest neighbours
Level L1 Beginner. Length One-liner. Nature Th Theoretical.

What's being asked

Whether you know that k-NN learns no weights, so the distance alone decides which features matter.

Key idea

k-NN usually uses Euclidean distance, ∥x−z∥2=∑j(xj−zj)2, where xj is the j-th feature of point x. A feature with a large numeric range dominates this sum. Standardising, xj←(xj−μj)/sj with μj the feature's mean and sj its standard deviation, puts every feature on the same scale.

Steps

  1. Say what k-NN does: it predicts from the labels of the k closest training points, so the distance decides everything.
  2. Give an example. Income in rupees varies by about 105; age in years varies by about 102. The squared income gap is far larger, so age is effectively ignored.
  3. Give the fix: use z-score scaling (subtract the mean and divide by the standard deviation) or min-max scaling (map each feature to [0,1]), computing μj and sj on the training set only and reusing those same values on test points.

Common mistakes

How long your answer should be

One sentence, plus the income-and-age example if asked why.

Read this

Previous in Supervised learning: What is the difference between multiclass and multilabel classification? Can you give one everyday example of each?
Next in Supervised learning: What is the difference between bagging and boosting, in one sentence?