The k-Nearest Neighbours algorithm classifies new data points based on their k nearest neighbours in feature space — without training, purely through distances. This app makes the resulting decision boundaries visible in real time.
The app shows how the k-Nearest Neighbours algorithm works in a two-dimensional feature space. Two classes of data points — blue and red — are placed in a coordinate system. The coloured background visualises the decision boundary: every position in the space is coloured blue or red according to its k nearest neighbours.
kNN is a so-called non-parametric algorithm: there is no training phase in the classical sense. Instead, new data points are classified at runtime by determining their k nearest neighbours in feature space and evaluating their classes by majority vote. The algorithm is intuitively understandable, but computationally intensive for large datasets.
Use the slider at the top to set k — the number of neighbours considered. Small k values produce complex, irregular boundaries; large k values progressively smooth the decision surface.
New data points can be added using the blue and red plus buttons on the right. Existing points can be moved with the mouse or removed by dragging them onto the bin icon at the bottom left. When moving the mouse within the area, the k nearest neighbours of the cursor are shown connected by lines.
Interested in AI visualisations for teaching?
The VisualApps are created as a teaching and transfer project at Reutlingen University and are used in corporate training and talks.
Get in touch