difficulty 2/5
Distance-weighted KNN
KNN where each neighbour's vote counts in inverse proportion to how far away it is — so a point sitting right next to the query outweighs one at the edge of the neighbourhood.
Intuition
Plain KNN has an odd blind spot: among the k neighbours, a point touching the query and a point at the far edge of the neighbourhood get exactly one vote each. That throws away information you already have — you know how close each one is.
Distance weighting uses it. Nearby neighbours count for more, distant ones for less, with influence falling off as distance grows. The prediction stops jumping as the k-th neighbour swaps for another one just behind it.
Formal definition
How it works
Where it's used
Why & when
Worked example
Pitfalls
Check yourself
3 questions
The questions on this page come with access. They are graded on the server, so the answers stay there until you have given yours.
Sources
- scikit-learn — KNeighborsClassifierdocs · retrieved 2026-08-31https://scikit-learn.org/stable/modules/generated/sklearn.neighbors.KNeighborsClassifier.html
- Dive into Deep Learning — Attention Pooling by Similaritybook · retrieved 2026-10-07https://d2l.ai/chapter_attention-mechanisms-and-transformers/attention-pooling.html