Add labeled training points, then click anywhere to classify a new point and see exactly which neighbors decided the vote.
KNN is arguably the simplest genuinely useful machine learning algorithm to understand, there's no training phase in the traditional sense, no weights to learn, no loss function to minimize. To classify a new point, KNN simply finds the K closest points in the training data (using distance, typically Euclidean distance) and takes a majority vote among their labels. Click "Classify New Point" and click anywhere on the chart above, the dashed circle shows exactly which training points fell within the K-nearest boundary, and the result shows exactly how the vote broke down.
Set K to 1 and the new point simply inherits the label of whichever single training point is closest, this makes the model extremely sensitive to noise, a single mislabeled or outlier training point can flip the prediction for an entire nearby region. Increase K and the prediction becomes an average over more neighbors, smoothing out noise but potentially blurring genuinely sharp boundaries between classes if K becomes too large relative to the dataset. There's no universally correct K, it depends on how much noise exists in your data and how cleanly separable the classes actually are, in practice, K is typically chosen via cross-validation, testing several values and picking whichever generalizes best to held-out data.
Unlike models that build an internal representation during a training phase (like the weights in a neural network, or the splits in a decision tree), KNN does essentially nothing at "training time", it just stores the entire dataset. All the actual computation happens at prediction time, when a new point needs classifying, KNN must compute its distance to every single stored training point. This is why KNN is called a "lazy learner", and it's also why KNN becomes genuinely slow on large datasets, classifying one new point requires comparing against every training example, an approach that doesn't scale gracefully to millions of data points without additional indexing structures.
Because KNN relies directly on distance calculations, features on very different numeric scales will distort results badly, a feature ranging from 0 to 1,000,000 will completely dominate the distance calculation over a feature ranging from 0 to 1, regardless of which feature is actually more informative for the classification task. This is exactly why standardizing or normalizing features to comparable scales before applying KNN isn't an optional preprocessing step, it's a genuine requirement for the algorithm to work correctly, unlike tree-based methods (like the Decision Tree visualizer on this site), which are naturally invariant to feature scaling.