#1 India's Top IT Training Institute

×

About Uncodemy

Know more about who we are and what we stand for.

About Us

About Us

Discover our mission to equip individuals with essential IT skills and industry expertise.

Read More →
UnCodeMy Gallery

UnCodeMy Gallery

Explore highlights from our IT training sessions and success stories.

Read More →
×

Free Resources

Learn, practice and plan your career — bilkul free.

Tutorials

Tutorials

Step-by-step written tutorials to learn any technology at your own pace.

Read More →
Free Counselling

Free Counselling

Book a free video counselling session and pick the right course for you.

Read More →
Online Compiler

Online Compiler

Write, run and test your code online — no setup required.

Read More →
🗳️ FREE · INTERACTIVE

KNN Classifier Visualizer: Let the Neighbours Vote

Click to place a point and see which class its k nearest neighbours choose.

  • 🖱️ Click to move the query
  • 🗺️ Decision regions
  • 📏 Euclidean or Manhattan

How to use the KNN Classifier Visualizer

  1. 1. Set up pointsKeep the sample or edit the list as x, y, class per line.
  2. 2. Place the queryClick the board or type its x and y.
  3. 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.

More free tools

See all free tools