In k-nearest neighbours classification, what happens to the decision boundary when k=1 and when k=n (the training set size)? How does this show the bias–variance trade-off, and how would you choose k?

Supervised learning, k-nearest neighbours
Level L1 Beginner. Length Short. Nature Th Theoretical.

What's being asked

Whether you can link k to model flexibility and name a sensible way to choose it.

Key idea

Small k gives a wiggly boundary (low bias, high variance); large k gives a smooth boundary (high bias, low variance).

Steps

  1. For k=1, each test point copies the label of its single nearest training point. The training error is zero, and the boundary follows every point, including noisy ones. This is low bias but high variance.
  2. For k=n, every test point is compared with all training points, so every point gets the majority class of the whole training set. The boundary disappears. This is very high bias, very low variance.
  3. Intermediate k averages over a neighbourhood: more neighbours cancel noise (less variance) but the neighbourhood grows and mixes classes (more bias).
  4. Choose k by cross-validation on a validation set, never on the training set (where k=1 always looks best). For two classes, use odd k to avoid ties.

Common mistakes

How long your answer should be

4–5 sentences.

Last checked on 4 December 2026.

Read this

Previous in Supervised learning: What is the difference between a generative and a discriminative classifier? What is one example of each, and when would you prefer each?
Next in Supervised learning: What is a kernel density estimate (Parzen window estimate), and what does the bandwidth h control? Why is the method called non-parametric?