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, , where is the -th feature of point . A feature with a large numeric range dominates this sum. Standardising, with the feature's mean and its standard deviation, puts every feature on the same scale.
Steps
- Say what k-NN does: it predicts from the labels of the closest training points, so the distance decides everything.
- Give an example. Income in rupees varies by about ; age in years varies by about . The squared income gap is far larger, so age is effectively ignored.
- Give the fix: use z-score scaling (subtract the mean and divide by the standard deviation) or min-max scaling (map each feature to ), computing and on the training set only and reusing those same values on test points.
Common mistakes
- Computing the scaling statistics on all the data, including the test set. This leaks test information into training.
- Assuming decision trees need scaling too. A tree splits on one feature at a time, so rescaling a feature does not change it.
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?