aNet.ai
Machine Learning/Learning path
0day streak0XP · Lv 1
← 12. Nearest-Neighbor & Probabilistic Methods
Lesson 1 of 4 9 min · 159 words

k-Nearest Neighbors

Vote (or average) among the k closest training points.

k-nearest neighbours (k-NN) has no training phase: it simply stores the data. To predict for a new point, find the training points closest to it and take a majority vote of their labels (classification) or the average of their targets (regression).

controls the bias–variance trade-off. follows every point, giving jagged boundaries and overfitting (zero training error). Large smooths the boundary and eventually underfits — with , it always predicts the majority class. Choose by cross-validation; odd avoids ties in binary problems.

Variants weight neighbours by inverse distance, so closer points count more.

Pros: simple, no assumptions about the data's shape, naturally multiclass. Cons: prediction is slow ( per query without index structures like KD-trees), memory-heavy, and suffers badly in high dimensions.

Formula to remember

k-NN prediction

Majority vote among the k nearest neighbours.

Quick check · +5 XP

k = 1 in k-NN usually gives…

Practice this topic
Saved in this browser as you type.
aNet.ai · Introduction to Machine Learning · NewUU course outlineProgress saved in this browser