1. k-nearest neighbour (kNN)
kNN stores the training set. To classify a query :
- Compute the distance from to every training point.
- Take the nearest.
- Predict the majority class among them (for kNN regression, predict their average ).
Common distances: Euclidean , Manhattan , and Minkowski (which gives Manhattan for and Euclidean for ). To find the nearest points you can compare squared Euclidean distances and skip the square root.
Properties:
- Lazy / instance-based: no training phase; prediction costs per query with brute force.
- Non-parametric: the boundary can take any shape; it is piecewise linear for 1-NN (a Voronoi partition).
- Choose odd for two classes to avoid ties; a distance-weighted vote (weight ) is a common variant.
- Feature scaling matters: a feature measured in large units dominates the distance, so standardise first.
- In high dimensions all distances become similar (curse of dimensionality), and kNN degrades.