▶ Interactive Lab

k-NN Classifier

Place training points; classify queries by k nearest neighbors.

Advertisement
click left half = train, click right half = classify
Each click adds a training point (left) or queries (right). Color = predicted class.

What you're seeing

k-NN: for each query, find k nearest training points; predict the majority class.

Simple but powerful baseline. No training phase — but every query searches all training points (O(n) per query without index). Vector databases solve this with ANN indexes.

★ KEY TAKEAWAY
k-NN: for each query, pick majority class of k nearest training points. Simple but powerful baseline.
▶ WHAT TO TRY
  • Click left half to add training points.
  • Click right half to classify queries.
  • Larger k = smoother boundary; smaller k = more local.