KNN Neighborhood Explorer

Watch k, distance metric and feature scaling reshape a k-nearest-neighbour decision boundary.

  • k-NN
  • decision boundary
  • scaling
  • bias-variance

Query prediction

Patient #0 is truly benign. Averaging the 9 nearest neighbors in 20 dimensions gives a predicted probability of 0.111 (cohort prevalence: 0.217).

Neighborhood in 2D PCA projection

-4-3-2-1012345-4-3-2-101234PC1PC2

Distance from query to every other case

k boundary0204060801001200123456789Rank (closest → farthest)Euclidean distance

Prediction for this patient as k grows

prevalence5101520253035404500.20.40.60.81kPredicted probability

Curse of dimensionality: distance concentration

24681012141618200123456789Number of dimensionsAverage distance
Nearest neighborFarthest neighbor
When 'nearest' stops meaning anything
As dimensions increase, the nearest and farthest curves converge: the ratio of nearest to farthest distance approaches 1, and every point becomes roughly equidistant from every other point. Reduce "Dimensions used" back toward 2 and watch the neighborhood snap back into a meaningful local structure.