K-Nearest Neighbors, One Neighbor at a Time
K-Nearest Neighbors (K-NN) may be the simplest classifier there is: to label a new point, look at the k labeled points closest to it and take the majority.
The steps
Pick k, the number of neighbors to ask.
Measure the distance from the new point to every point in the training data, usually with the Euclidean distance.
Take the k nearest and let them vote; for a regression, average their values instead.
Choosing k
A small k follows the training data closely and reacts to every noisy point. A large k smooths the boundary but may blur classes together. An odd k avoids ties between two classes, and cross-validation helps pick the value that generalizes best.
Scale matters
Distances mix every feature, so a feature measured in thousands drowns one measured in fractions. Normalize the features first, for example to the range 0 to 1, or K-NN will only listen to the largest numbers.
Share

