KNN (K-Nearest Neighbors)
The K-nearest-neighbors method. The model does not look for a general formula: it simply looks at the \(K\) most similar objects from the training set and takes their answer.
How It Works
- Every object is a point in the space of features.
- Compute the distance to every training object (metric: Euclidean, Manhattan and others).
- Take the \(K\) nearest ones.
- For classification — majority voting; for regression — averaging.
About \(K\)
\(K\) is a hyperparameter:
- a small \(K\) → sensitivity to noise, risk of overfitting;
- a large \(K\) → heavy smoothing, risk of underfitting.
Specifics
- before running, the features are usually scaled;
- in high-dimensional spaces it performs worse because of the curse of dimensionality;
- there is no training as such: the model is 'lazy' — all the computation happens at inference time.