K-Nearest Neighbors
See distances, the nearest K samples, votes, and the local decision boundary.
KNN stores training samples and predicts from nearby examples. It does not learn iterative parameters, so ModelOrigen visualizes real distances, neighbors, votes, and the resulting boundary instead of inventing epochs.
Step by step
- Store the training samples.
- Choose a query point.
- Measure distance from the query to every training sample.
- Sort by distance and keep the closest K.
- Combine uniform or distance-weighted votes.
- Return the predicted class and inspect the local boundary.
Core formulas
Euclidean distance
d(x,z) = √Σ(xⱼ − zⱼ)²Straight-line distance in feature space.
Distance weighting
weightᵢ = 1 / max(dᵢ, ε)Closer neighbors can receive more influence when distance weighting is enabled.
When to use K-Nearest Neighbors
- The dataset is not huge and local similarity is meaningful.
- A nonlinear local boundary is useful.
- You want a simple instance-based baseline.