K-nearest Neighbors (KNN)
Last Updated: July 29, 2026 | By Mihail Sebastian | AI Dictionary
A supervised algorithm that predicts a point's label from the labels of its K closest training points. No training phase: all work happens at prediction time.
What is K-nearest Neighbors?
K-nearest neighbors (KNN) is a supervised learning algorithm that predicts a data point’s label from the labels of the K most similar points in the training data: majority vote for classification, average for regression.
It is the plainest form of instance-based learning. There is no training phase and nothing is fitted; the stored data itself is the model. Despite the shared letter, it is not k-means clustering, which is unsupervised and groups unlabeled data.
How KNN Works
To classify a new point, KNN computes its distance to every point in the training set, usually Euclidean distance, and takes the K closest. Their majority label is the prediction. Because raw distances mix units (income in thousands, age in years), features must be scaled first or the largest-valued feature dominates.
K is the knob. A small K reacts to every local quirk and picks up noise; a large K smooths over real local patterns. Practitioners choose it by cross-validation.
The deferred work has a cost. Prediction means measuring distance to the entire training set, so KNN slows as the data grows, the opposite profile of models that train slowly and predict fast.
Example of K-nearest Neighbors
A streaming service wants to guess whether a user will enjoy a particular film. It represents every subscriber as a point built from their ratings history, then finds the five subscribers most similar to this user.
Four of those five rated the film highly. By majority vote, KNN predicts this user will like it too, and the film goes into their recommendations row. No model was ever trained; the service just asked the neighbors.
The same mechanism runs anomaly detection in reverse: a transaction whose nearest neighbors are all far away resembles nothing seen before, which is reason to flag it.
Related AI terms: Support Vector Machine · Decision Tree · Instance-Based Learning · K-Means Clustering
Did you like the K-nearest Neighbors (KNN) gist?
Learn about 250+ need-to-know artificial intelligence terms in the AI Dictionary.
Mihail Sebastian — Writes about AI governance, regulation, and the technology behind them. Placeholder bio — replace with a real credential line. About