AlgoPlus//machine learning / knn
Read the theory

k-Nearest Neighbors

Classify a new point by the majority vote of its k closest neighbours.

k
3
Query
(5, 5.5)
Prediction
Legend
Class 1
Class 0
Query point
AI Tutor Workspace
In a nutshell
k-nearest-neighbours labels a new point by looking at the labelled examples sitting closest to it and taking a majority vote. There's no training step at all — it just stores the data and measures distances when a question arrives. A small k follows the nearest few closely; a larger k averages over a wider neighbourhood.
Ready
Press play to begin the cinematic walkthrough.
No training at all — to judge a newcomer, look at who it's standing closest to and go with the crowd. Small k trusts the nearest gossip; large k polls a wider room.
Key terms
Go deeper in the lesson
Read the full theory, intuition & complexity for k-Nearest Neighbors.