Feature Scale in a Distance-Based Model

Distance can be dominated by variables with large numerical scale, even when all features are meant to have comparable influence.

Source
Anbloq
Language
English
Created
Updated
Chapters
4
Reading time
1 min
In this article4 chapters
  1. Trace two differences
  2. Fit transformations appropriately
  3. Show how units can change the nearest neighbor
  4. Choose scaling from the model's purpose

Trace two differences

A difference of three in a count and 1000 in milliseconds yields a Euclidean distance dominated by the latter. Converting milliseconds to seconds changes the comparison. See numeric vector distances.

Fit transformations appropriately

A model can scale each feature according to a documented policy. Compute statistics using training data where the scale is learned, and carry them to later inputs. See evaluation leakage.[1]

Show how units can change the nearest neighbor

Query \((0,0)\) has points A \((3,1)\) and B \((1,4)\). In raw Euclidean coordinates, A is closer since squared distances are ten and seventeen. Multiplying only the first coordinate by ten gives squared distances 901 and 116, making B closer. See distance metrics.

Raw A=10, B=17 in squared distance
Rescaled x: A=901, B=116
Nearest neighbor changes from A to B

Choose scaling from the model's purpose

Standardization can make scales comparable under one convention, while a domain may want a stronger weight for one feature. Fit transformations on training data and test effect on a few known neighbor relationships.

References

  1. Gareth James et al., An Introduction to Statistical Learning ↩