How does the choice of k in k-Nearest Neighbors affect the model's bias and variance?

Quick Overview

Asks how the number of neighbors k in k-Nearest Neighbors moves the model between underfitting and overfitting. Tests whether you can explain the bias and variance at small and large k, the limiting cases, and how to choose k with cross-validation and scaled features.

How does the choice of k in k-Nearest Neighbors affect the model's bias and variance?

Role: Machine Learning Engineer

Category: Machine Learning

Difficulty: easy

Interview Round: Other

How does the choice of `k` in k-Nearest Neighbors affect the model's bias and variance? ```hint Look at the extremes Think about what the prediction looks like at k = 1 and at k = n, where n is the size of the training set. ``` ### What a Strong Answer Covers - Which direction small and large k move bias and variance, and the mechanism behind each. - The limiting cases k = 1 and k = n. - A quantitative link between k and model capacity. - How to choose k in practice, including cross-validation and feature scaling. ### Follow-up Questions - How does the best k change as the training set grows, and as the number of features grows? - How does distance-weighted kNN change the bias-variance behavior compared with uniform weights? - Why is training error useless for picking k, and how would you compute leave-one-out error for kNN cheaply?

Overview: Asks how the number of neighbors k in k-Nearest Neighbors moves the model between underfitting and overfitting. Tests whether you can explain the bias and variance at small and large k, the limiting cases, and how to choose k with cross-validation and scaled features.

PracHub logo
General
Nov 25, 2026
easyMachine Learning EngineerOtherMachine Learning
0
0

How does the choice of k in k-Nearest Neighbors affect the model's bias and variance?

What a Strong Answer Covers Guidance

  • Which direction small and large k move bias and variance, and the mechanism behind each.
  • The limiting cases k = 1 and k = n.
  • A quantitative link between k and model capacity.
  • How to choose k in practice, including cross-validation and feature scaling.

Follow-up Questions Guidance

  • How does the best k change as the training set grows, and as the number of features grows?
  • How does distance-weighted kNN change the bias-variance behavior compared with uniform weights?
  • Why is training error useless for picking k, and how would you compute leave-one-out error for kNN cheaply?