Nearest Neighbours and the Curse of Dimensionality
Consistency of k-NN, the exact rate under smoothness, and the concentration argument that explains why it fails in high dimension.
The rule and its asymptotics
Given and a query , order the training points by distance to and average the labels of the closest.
For the zero-one loss with , the asymptotic risk of the -nearest-neighbour rule satisfies
where is the Bayes risk.
If and , then the -NN rule is universally consistent: its risk converges to the Bayes risk for every distribution on , with no smoothness or density assumptions whatsoever.
Both are quoted from the references. Stone's theorem is a remarkable statement — there is a fully distribution-free learning rule — and it is worth pausing on why it does not contradict no free lunch. The resolution is that consistency is an asymptotic statement with no rate: for every distribution the risk eventually converges, but the sample size at which it becomes small depends on the distribution, and no free lunch says that dependence cannot be bounded uniformly.
Let with being -Lipschitz on , , and having a density bounded above and below on . Then the -NN regression estimate satisfies, at a fixed interior point,
which is minimised at , giving
Key idea
The exponent is the curse of dimensionality written as a number. To reach accuracy one needs samples — exponential in . At and that is samples; at it is . And this rate is minimax optimal over the Lipschitz class, so no method does better: the problem is hard, not the algorithm.
Contrast this with the sample complexity of covariance estimation. Both are called "the curse of dimensionality" and they differ by an exponential. The difference is parametric versus nonparametric: assuming a parametric form is what converts into .
Why distances stop being informative
Let be i.i.d. with independent coordinates of unit variance and bounded norm in . Then
for fixed , and more quantitatively, with probability at least ,
while both are of order .
What this does not say
Read the hypotheses. The coordinates are assumed independent and identically scaled. That is the worst case for nearest neighbours and it is not what real data looks like. The proposition says: if your data is isotropic noise, distances carry no information. It does not say nearest-neighbour search is meaningless on real high-dimensional data, and interpreting it that way is a misreading that was common for years after Beyer et al. raised the question.
Empirical observation — a regularity seen in experiments. No theorem on this page establishes it in general.
-NN and approximate nearest-neighbour search perform far better on real high-dimensional data — image embeddings, text embeddings, audio features — than the rate with the ambient dimension would allow.
What this does not say
The standard explanation is that the data concentrates near a low-dimensional structure, so the relevant exponent involves the intrinsic dimension rather than the ambient one. There are theorems supporting this: under a manifold assumption the -NN rate becomes , and doubling-dimension conditions give similar results.
But this is not a complete explanation of practice, for two reasons. Estimating for real data is itself hard and the estimates are unstable. And the manifold hypothesis is an assumption about data that is rarely tested in the settings where it is invoked. The honest position: the gap between the isotropic worst case and observed performance is real, low intrinsic dimension is the best available explanation, and it has not been verified quantitatively for the embeddings used in production retrieval systems.
Problems
The k-NN bias–variance balanceProof · Advanced · 1 hour Distance contrast and the failure of nearest neighboursProof · Intermediate · 30 min Two different curses of dimensionalityNumerical · Beginner · 15 min Simulate distance contrastCoding · Beginner · 30 minReferences
- PaperThomas M. Cover and Peter E. Hart (1967). Nearest neighbor pattern classification
- PaperCharles J. Stone (1977). Consistent nonparametric regression
- BookLászló Györfi, Michael Kohler, Adam Krzyżak and Harro Walk (2002). A Distribution-Free Theory of Nonparametric Regression
- PaperKevin Beyer, Jonathan Goldstein, Raghu Ramakrishnan and Uri Shaft (1999). When Is Nearest Neighbor Meaningful?
These works are cited as sources to read, not reproduced. All exposition, examples and problems on this site are written independently; where an argument is standard, the citation points to a canonical treatment.
Results stated on this page
- TheoremCover–Hart inequality for 1-NNThe asymptotic risk of the 1-nearest-neighbour rule is at most twice the Bayes risk.
- TheoremUniversal consistency of k-NNWith k growing and k/n going to zero, the k-NN risk converges to the Bayes risk for every distribution.
- TheoremNonparametric rate for k-NN regressionproof includedUnder Lipschitz smoothness the excess risk is of order n to the minus two over d plus two.
- PropositionDistance contrast vanishes in high dimensionproof includedThe ratio of the farthest to the nearest distance among n random points tends to one as the dimension grows.
- Empirical observationNearest neighbours work better than the theory predictsReal data concentrates near low-dimensional structure, so the relevant exponent is the intrinsic dimension.