Suppose you move to a new city and need to decide whether a neighborhood is safe. The simplest strategy: find the k nearest residents who look similar to your situation and ask what they think. If most say safe, you go with safe. No statistics textbook required.
k-Nearest Neighbors (k-NN) works exactly that way. Given a set of labeled training points and a new query point, it finds the k closest training examples, counts which class appears most often among them, and assigns that class to the query. No parameters to optimize, no model to fit, no training phase at all — just store the data and measure distances when a query arrives.
Formally proven by Thomas Cover and Peter Hart in 1967, k-NN carries a beautiful theoretical guarantee: as the number of training points grows to infinity, its error rate is never worse than twice the optimal Bayes error rate. That theoretical anchor, combined with near-zero setup cost, made k-NN one of the foundational tools in machine learning — and a benchmark that fancier algorithms still have to beat on small datasets.
The price you pay comes at query time. Every prediction requires scanning (or smartly indexing) the entire training set, making k-NN a deceptively expensive algorithm once data grows large.
Comments
Loading comments...