An appraiser pricing a house looks at comparable sales: the five most similar recently sold homes nearby, by size, bedrooms and location. Averaging their prices gives an estimate. That is k-nearest neighbors with k = 5. For a yes-or-no question, such as whether a transaction is fraud, the five nearest past cases vote instead.
There is almost no training step. The method stores the labeled examples and does its work when a question arrives, so adding new examples changes its answers immediately. The results depend on what “similar” means. If one column is price in dollars and another is number of bedrooms, the dollar column swamps the distance unless both are scaled. With many columns, everything starts to look roughly equally far away, which makes the neighbors less meaningful.
The find-the-closest step is the same one behind semantic search and vector databases, which look up the nearest embeddings to a query, usually approximately for speed. k-NN adds the vote or average over those neighbors’ known answers. Despite the similar name, k-means clustering is an unlabeled grouping method, not a predictor.
Sources
- scikit-learn: Nearest Neighbors classification — Describes neighbors-based classification as instance-based learning that stores the training data and predicts by majority vote of the nearest neighbors, and notes it becomes less effective in high dimensions; checked October 24, 2026.
- scikit-learn: KNeighborsClassifier — Documents the n_neighbors, weights and distance metric settings that control which neighbors vote and how much; checked October 24, 2026.