K-Nearest Neighbors Demo

An interactive demonstration of the K-Nearest Neighbors (KNN) classification algorithm. Create your own dataset and see how KNN makes predictions in real-time.

K-Nearest Neighbors Classification
K neighbors:
3
Click to add training points. Hold Shift and click to add a point to predict. The prediction point will be classified based on its K nearest neighbors.

How to Use

1. Select a class (A or B) using the buttons above the canvas

2. Click anywhere on the canvas to add training points of the selected class

3. Use the slider to adjust the number of neighbors (K) considered for classification

4. Hold Shift and click to place a prediction point - it will be classified based on its K nearest neighbors

5. Use the Clear All button to reset the demonstration