ML model visualizer

K-Nearest Neighbors

Explore how nearby examples drive classification and regression predictions.

TaskClassificationLearningLazy LearningDistanceEuclideanOutputClass Label
115

Decision Space

Class regions
-5-3-1135-5-3-1135XY
Class AClass BQuery pointNearest neighbor

Click the chart to move the query point, then run prediction.

PredictionReadyChoose a query point and inspect its 5 nearest neighbors.

Metrics

Classes / points2 / 24
Neighbors found0
ConfidencePending

Nearest Neighbors

RankClassDistance
Run prediction to inspect neighbors.

How KNN Works

  1. Measure distance from the query to every training point
  2. Sort all points by increasing distance
  3. Select the K nearest neighbors
  4. Count the class labels among those neighbors
  5. Return the class with the most votes