K-nearest neighbors (KNN) is a non-parametric lazy-learning algorithm: training only stores the data (zero training cost); at prediction time it finds the
K closest training samples to the input — majority voting for classification, mean for regression.Distance-weighted voting often improves robustness:
wi=d(x,xi)1 or
wi=d(x,xi)21, giving nearby neighbors more say; the decision boundary is set by the training points' Voronoi regions.Too-small K → high-variance overfitting (a single neighbor decides), too-large K → high-bias underfitting (distant classes intrude); cross-validation picks K.Curse of dimensionality: in high dimensions samples are sparse, all pairwise distances converge, the relative spread
dmax−dmin collapses, neighbors are almost equidistant and discrimination degrades toward random — mitigated by dimensionality reduction or feature selection.