All labs

k-NN Boundaries, Bias–Variance, and the Bayes Floor

Watch the decision boundary go from memorized to over-smoothed, with training error at zero the whole time it is useless.

Ch 5 5.3
Explorer
Supervised Learning
18 mindifficulty 3/5

Controls

1

k = 1 memorizes; large k averages the whole cloud.

Class geometry
0.900

Sets the irreducible Bayes error.

200
40

Grid points per side used to paint the decision region.

Random seed

Every result on this page is a deterministic function of the seed and the controls.

Decision boundary

Background shading is the k-NN vote; points are the training sample.

-4-2024-4-2024x₁x₂
class 0class 1

Error against model complexity

Training error at k = 1 is zero and tells you nothing.

00.100.200.300.400.5020406080100k = 1k (complexity decreases to the right)misclassification rate
training (resubstitution)held-out testBayes error
Test error
16.0%
400 fresh points
Resubstitution error
0.0%
the point is its own neighbour
Leave-one-out error
15.5%
honest use of the training data
Bayes error
9.1%
irreducible at this overlap
Best k on test
35
error 10.3%
Effective parameters
200
≈ n/k regions of the input space
Zero training error is not skill

At k = 1 every training point is its own nearest neighbour, so resubstitution error is exactly 0 for any data whatsoever — including pure noise. The leave-one-out and test readouts are the ones that carry information.