ClassificationSample
k-nearest neighbours
Classifies a point by the majority class among its k nearest neighbours.
Synthetic data, generated and trained in your browser.
Try this
- 01Set k = 1 on Moons: stray points get their own little islands.
- 02Turn on the test split and slide k from 1 to 40: test accuracy rises, then falls.
- 03Switch to Manhattan distance and compare the shape of the boundary.
How it works
- 1Store the labelled points.
- 2For a new point, find the k closest by the chosen distance.
- 3The share of each class among them is the predicted probability.
What the controls teach
- Neighbours k
- Neighbourhood size. Small k gives jagged, noise-sensitive boundaries; large k smooths them.
- Distance
- Euclidean measures straight-line distance; Manhattan sums horizontal and vertical steps, giving boxier regions.
Use it when
- Irregular boundaries in low dimensions
Avoid it when
- Many features (distances lose meaning)
- Large training sets at prediction time
More in Classification
Logistic regression
Models the probability of a class with a weighted sum passed through a sigmoid.
Decision tree
Learns a sequence of yes/no questions on the features that ends in a class.
Naive Bayes (Gaussian)
Applies Bayes’ theorem, assuming each feature is normally distributed and independent within a class.