Nearest Neighbor Is Never More Than Twice as Bad as Bayes
Field: ML / Statistics (nonparametric classification) Estimated difficulty: 2 / 5
Setup
Consider two-class classification. A feature vector has a density, and the label is . Write for the posterior, and assume is continuous.
- The Bayes classifier predicts exactly when . Its error rate is
- The 1-nearest-neighbor (1-NN) classifier is trained on i.i.d. pairs . At a query point , it predicts the label of the training point closest to .
As , the nearest neighbor of converges to . Take this as given.
Questions
(a) Show that the asymptotic 1-NN error rate is
(b) Prove the CoverโHart bounds
(c) (Bonus) Now allow classes with posteriors . Show that
Why this is interesting
The 1-NN rule has no model, no parameters, and no training. Yet with infinite data it is guaranteed to lose at most a factor of 2 against the best possible classifier, whatever the distribution. Informally: half of all the classification information in the world is contained in the label of your nearest neighbor. The proof is a short pointwise inequality followed by one application of Jensen's inequality.
Reference: Hastie, Tibshirani, Friedman, The Elements of Statistical Learning (2nd ed.), ยง13.3 (the 1-NN asymptotic error bound and the -class formula). Original result: T. Cover & P. Hart, "Nearest neighbor pattern classification," IEEE Trans. Inf. Theory, 1967.
Answer: Nearest Neighbor Is Never More Than Twice as Bad as Bayes
Key Idea / Intuition
With infinite data, your nearest neighbor sits essentially on top of you. Its label is therefore an independent draw from the same coin as your own label. So 1-NN errs exactly when two independent flips of the same biased coin disagree, which happens with probability .
Bayes, by contrast, errs with probability . Since lies between and , we get the pointwise bounds. The function is concave, so Jensen's inequality averages the pointwise bound into the sharper global bound .
Formal Proof / Solution
(a) The asymptotic error
Fix a query point . Let be its true label and the label of its nearest neighbor .
Given the feature values, the labels are drawn independently:
- ,
- .
As , we have . By continuity, .
The classifier errs exactly when . So the conditional error converges to
The conditional error is bounded by , so dominated convergence lets us take expectations over :
(b) The CoverโHart bounds
Let . By symmetry,
Lower bound. Since , we have . Hence Taking expectations gives .
This is also clear without calculation: no rule beats Bayes.
Upper bound. The function is concave. By Jensen's inequality,
Finally, is trivial.
Remarks.
- The pointwise bound alone, , already gives the factor 2.
- Jensen sharpens it to . Equality holds when is almost surely constant, for example when noise is uniform across feature space.
- When (separable classes), 1-NN is asymptotically perfect.
- When (pure noise), both rules have error .
(c) classes
At a point , let the posteriors be . Let be the index of the largest posterior, and set . Then is the Bayes error at .
The NN error at . By the same argument as in (a), the true label and the neighbor's label are independent draws from . Hence
Bounding the sum of squares. The other probabilities sum to . By CauchyโSchwarz, Therefore
Averaging. The function is concave in , and . By Jensen,
For this reduces exactly to .
Moral. The whole proof rests on two observations. First, an asymptotic nearest neighbor is an independent copy of your own label. Second, the map from Bayes error to NN error is concave, so averaging over feature space can only help the bound.
Caveat. The result is asymptotic. In high dimensions, happens extremely slowly (the curse of dimensionality), so finite- performance can be far worse than this bound suggests.
Source: Hastie, Tibshirani, Friedman โ The Elements of Statistical Learning (2nd ed.), ยง13.3; Cover & Hart (1967)