K-Nearest Neighbors (KNN) Playground

Visualize distance metrics, neighborhood voting matrices, and localized decision boundaries live.

Class Red
Class Blue
Query Point (X)
Distance Radius

Confusion Matrix (Leave-One-Out Evaluation)
Predicted Red (+)
Predicted Blue (-)
Total
Actual Red
0 0.0% True Red (TP)
0 0.0% False Blue (FN)
0
Actual Blue
0 0.0% False Red (FP)
0 0.0% True Blue (TN)
0
Total
0
0
0
K Neighbors Value3
Tip: Use odd numbers for binary classification to avoid tie votes!

Ensemble Vote Tally Matrix
Closest Neighbors found: 0
Vote Breakdowns: N/A
🔬 Classroom Demonstration: Put the app in "Move Query Point" mode. Place it directly inside a dense blue cluster. Now, ramp K up to **15**. Notice how the point can switch to Red if there are more red points globally nearby, showcasing how a large K underfits local structures! The system Confusion Matrix updates automatically based on a global Leave-One-Out validation strategy.