PPolySim OS

k-Nearest Neighbors

The laziest classifier that works: to label a point, just ask its nearest neighbors to vote. Watch the decision regions shift as you change k.

k-Nearest NeighborsLive

Controls

Presets

k-NN classifies a point by majority vote of its k nearest labeled neighbors. Small k gives jagged, overfit boundaries that chase noise; large k smooths them out but can blur real structure. It is the simplest possible classifier — no training at all. Educational tool.

▶ Run in Python

Data Inspector

Neighbors5
Boundarybalanced

Governing equation

Reading this result: k = 5 sits in the sweet spot: enough neighbors to shrug off noise, few enough to keep the true boundary shape.

Runs locally in your browser — free forever. Scale to the cloud when reality gets heavy.

or unlock everything with Pro →
★ Sign in to save this setup
Save your tuned setup, or drop this simulation into your own site, docs, or course page.

How it works

k-NN stores the training data and classifies a new point by majority vote of its k closest examples. A small k hugs every point (low bias, high variance); a large k smooths the boundary (higher bias, lower variance). It needs no training but grows costly at prediction time. Educational tool.

Ask the AI about this model

The math, the assumptions, real-world uses, or a code translation — explained for this exact simulation.

More CS / AI simulations

Frequently asked questions

Is this knn classifier simulator tool really free?
Yes. k-Nearest Neighbors runs entirely in your browser using your device's own compute, so local use is free forever. You only pay Compute Tokens if you scale a job to the cloud.
Do I need to install anything?
No. Everything runs client-side in a modern browser — no downloads, no license, no account required to start.
Can I save or share my simulation?
Create a free account to save projects, and use a shareable embed or minted DOI to publish a live, interactive version anywhere.
How accurate are the results?
The solver uses established numerical methods, but results are for research and educational purposes and should be validated against experiment or professional review before you rely on them.