How does inverse-distance weighting work in KNN regression?

Quick Overview

Asks how inverse-distance weighting turns the k nearest neighbors' targets into a regression prediction. Tests your grasp of the weighting formula, the effect of the distance power, the zero-distance case, and how the method compares with a plain neighbor average.

How does inverse-distance weighting work in KNN regression?

Role: Machine Learning Engineer

Category: Machine Learning

Difficulty: medium

Interview Round: Other

In k-nearest neighbors regression, the prediction for a new point comes from the targets of its $k$ closest training points. How does inverse-distance weighting work in KNN regression, and how does it change the prediction compared with a plain average? ```hint Write the formula Write the prediction as a weighted average and check what happens to it as one neighbor's distance shrinks toward zero. ``` ### What a Strong Answer Covers - The weighted-average formula and why the weights are normalized. - The effect of the power $p$ in the weight, including the $p = 0$ case. - How it compares with the uniform average in bias, variance and sensitivity to $k$. - The zero-distance case and how to handle it. - Preprocessing needs and limits, such as feature scaling and the lack of extrapolation. ### Follow-up Questions - What does distance weighting do to training-set error, and why does that matter for model selection? - How would you choose $k$ and $p$ together? - Why does distance weighting help less in high-dimensional feature spaces? - What changes if you replace ${1/d^p}$ with a Gaussian kernel, and what does its bandwidth control?

Overview: Asks how inverse-distance weighting turns the k nearest neighbors' targets into a regression prediction. Tests your grasp of the weighting formula, the effect of the distance power, the zero-distance case, and how the method compares with a plain neighbor average.

General logo
General
Nov 24, 2026
mediumMachine Learning EngineerOtherMachine Learning
0
0

In k-nearest neighbors regression, the prediction for a new point comes from the targets of its kk closest training points. How does inverse-distance weighting work in KNN regression, and how does it change the prediction compared with a plain average?

What a Strong Answer Covers Guidance

  • The weighted-average formula and why the weights are normalized.
  • The effect of the power pp in the weight, including the p=0p = 0 case.
  • How it compares with the uniform average in bias, variance and sensitivity to kk .
  • The zero-distance case and how to handle it.
  • Preprocessing needs and limits, such as feature scaling and the lack of extrapolation.

Follow-up Questions Guidance

  • What does distance weighting do to training-set error, and why does that matter for model selection?
  • How would you choose kk and pp together?
  • Why does distance weighting help less in high-dimensional feature spaces?
  • What changes if you replace 1/dp{1/d^p} with a Gaussian kernel, and what does its bandwidth control?