How to use the KNN Classifier Visualizer
- 1. Set up pointsKeep the sample or edit the list as x, y, class per line.
- 2. Place the queryClick the board or type its x and y.
- 3. ClassifySee the nearest neighbours, the vote and the shaded regions.
How KNN decides
k-nearest neighbours has no training step. To classify a new point it finds the k closest labelled points and takes a majority vote. Closeness is usually Euclidean distance, √((x₁ − x₂)² + (y₁ − y₂)²), or Manhattan distance, |x₁ − x₂| + |y₁ − y₂|.
Worked example (defaults, k = 3): the query is at (3, 3). The nearest points are (2, 3) at distance 1, (3, 1.5) at 1.5 and then (2, 1) at 2.2361. All three are class A, so the prediction is Class A (3 of 3 votes).
What to explore
- k = 1 gives jagged regions that follow every point; it overfits.
- Large k smooths the boundary but can drown small classes.
- Odd k avoids ties between two classes. Here, ties go to the class of the nearer neighbour.
- Manhattan vs Euclidean changes the region shapes, most visibly near boundaries.
Because KNN uses raw distances, features on bigger scales dominate. In real data, scale features first with the normalization calculator. KNN also slows down as data grows, since every prediction compares against all stored points. In scikit-learn: KNeighborsClassifier(n_neighbors=3). Compare it with unsupervised grouping in the k-means visualizer. The decision regions are found by classifying a grid of points across the board, so they show exactly what the model would answer anywhere.
Frequently asked questions
Can I add more classes?
Yes. Use any short label in the third column, such as A, B, C or D.
Is the board keyboard accessible?
Yes. Every point and the query can be typed in the inputs; clicking is optional.
Is the KNN Classifier Visualizer free?
Yes, the KNN Classifier Visualizer is free. The first time you classify your first point, you are asked for your name and WhatsApp number once. After that, this and every other Uncodemy tool opens straight away without the form.