Classification Space
Click anywhere to classify

Controls

What is KNN?

K-Nearest Neighbors is a simple yet powerful classification algorithm. It classifies a point based on the majority class of its K nearest neighbors.

How to Use

  • Click anywhere to classify that point
  • Watch the algorithm find K nearest neighbors
  • Adjust K to see how it affects classification
  • Try different distance metrics

Custom Mode

Select "Custom" dataset to draw your own training points. Switch between Add/Delete modes to create your dataset.

Algorithm Steps

  1. Calculate distance from query to all training points
  2. Sort points by distance (ascending)
  3. Select K nearest neighbors
  4. Count votes for each class
  5. Assign majority class to query

Distance Metrics

  • Euclidean: √(Σ(xᵢ - yᵢ)²)
  • Manhattan: Σ|xᵢ - yᵢ|
  • Chebyshev: max(|xᵢ - yᵢ|)

Weighted Voting

When enabled, closer neighbors have more influence. Each vote is weighted by 1/distance.

K Nearest Neighbors 0
Click to classify a point
K Metric Prediction Confidence
Classify a point to compare

Shows classification with different K values and metrics.