๐Ÿงฎ Brain Teaser

The Curse of Dimensionality: When Your "Nearest" Neighbor Is Far Away

Suppose you have nn training points drawn uniformly from the pp-dimensional unit hypercube [0,1]p[0,1]^p, and you want to use the 1-nearest-neighbor rule to predict at the center point x0=(1/2,1/2,โ€ฆ,1/2)x_0 = (1/2, 1/2, \ldots, 1/2).

To "capture" a fraction rr of the data (i.e., the expected fraction of training points within a hypercubic neighborhood of x0x_0), you need a neighborhood of edge length โ„“\ell where โ„“p=r\ell^p = r, so โ„“=r1/p\ell = r^{1/p}.

Question: For r=0.01r = 0.01 (capturing 1% of the data), compute โ„“\ell for p=1,2,10p = 1, 2, 10. What happens as pโ†’โˆžp \to \infty?

Then explain: why does this imply that 1-nearest-neighbor in high dimensions is essentially a global method, not a local one?

Finally, consider the expected prediction error (EPE) of 1-NN relative to OLS when the true model is linear: f(x)=x1f(x) = x_1. The EPE ratio starts at approximately 22 in low dimensions. Give an intuitive explanation for why this ratio is at least 2 even in p=1p=1.

curse of dimensionalityk-nearest neighborbias-variancehigh dimensionsEPE

Answer: Curse of Dimensionality: Nearest Neighbor Becomes Global

Key Idea / Intuition

In low dimensions, "nearby" means genuinely local. But in high dimensions, to find even a tiny fraction of your data, you must look almost everywhere in the cube โ€” the neighborhood that captures 1% of the data has edge length close to 1. This is the geometric heart of the curse of dimensionality: local methods become global, losing their ability to exploit local structure. The EPE ratio of 2 arises because 1-NN has irreducible variance equal to ฯƒ2\sigma^2 (from the label noise of the nearest neighbor itself), whereas OLS (under a correct linear model) has near-zero variance, so the 1-NN error is at least ฯƒbias2+ฯƒ2โ‰ฅฯƒ2\sigma^2_{\text{bias}} + \sigma^2 \geq \sigma^2, giving a ratio โ‰ฅ2\geq 2 against OLS's EPE โ‰ˆฯƒ2\approx \sigma^2.


Formal Proof / Solution

Part 1: Edge Length Computation

To capture fraction rr of uniformly distributed points, the hypercubic neighborhood of edge length โ„“\ell satisfies:

โ„“p=rโ€…โ€ŠโŸนโ€…โ€Šโ„“=r1/p\ell^p = r \implies \ell = r^{1/p}

For r=0.01r = 0.01:

| pp | โ„“=(0.01)1/p\ell = (0.01)^{1/p} | Interpretation | |-----|----------------------|----------------| | p=1p=1 | (0.01)1=0.01(0.01)^1 = 0.01 | 1% of the unit interval โ€” truly local | | p=2p=2 | (0.01)1/2=0.1(0.01)^{1/2} = 0.1 | 10% of each side โ€” already a large square | | p=10p=10 | (0.01)1/10=10โˆ’2/10=10โˆ’0.2โ‰ˆ0.63(0.01)^{1/10} = 10^{-2/10} = 10^{-0.2} \approx 0.63 | 63% of each side! |

As pโ†’โˆžp \to \infty: โ„“=r1/p=elnโกrpโ†’e0=1\ell = r^{1/p} = e^{\frac{\ln r}{p}} \to e^0 = 1

No matter how small r>0r > 0 is, the required edge length โ†’1\to 1 as pโ†’โˆžp \to \infty.

Part 2: Why 1-NN Becomes Global

A neighborhood capturing only 1% of the data already spans 63% of each coordinate axis in p=10p=10 dimensions. The "nearest neighbor" is no longer near โ€” it could be almost anywhere in the cube. The implicit smoothness assumption ("nearby points have similar labels") completely breaks down. The method is forced to interpolate across the entire feature space, making it no more "local" than a global method.

Part 3: EPE Ratio โ‰ฅ 2 Even at p=1p=1

For the model Y=f(X)+ฮตY = f(X) + \varepsilon with ฮตโˆผ(0,ฯƒ2)\varepsilon \sim (0, \sigma^2), the EPE of any predictor f^(x0)\hat{f}(x_0) decomposes as:

EPE=Bias2(f^(x0))+Var(f^(x0))+ฯƒ2\text{EPE} = \text{Bias}^2(\hat{f}(x_0)) + \text{Var}(\hat{f}(x_0)) + \sigma^2

For OLS (correct linear model): bias =0= 0, variance โ‰ˆ0\approx 0 for large nn, so: EPEOLSโ‰ˆฯƒ2\text{EPE}_{\text{OLS}} \approx \sigma^2

For 1-NN: The prediction is f^(x0)=Y(1)=f(x(1))+ฮต(1)\hat{f}(x_0) = Y_{(1)} = f(x_{(1)}) + \varepsilon_{(1)}, where x(1)x_{(1)} is the nearest training point. There are two sources of noise:

  1. Noise in the label: ฮต(1)โˆผ(0,ฯƒ2)\varepsilon_{(1)} \sim (0, \sigma^2) โ€” irreducible, contributes +ฯƒ2+\sigma^2
  2. Distance bias: f(x(1))โ‰ f(x0)f(x_{(1)}) \neq f(x_0) because x(1)โ‰ x0x_{(1)} \neq x_0 โ€” contributes additional error

Thus: EPE1-NN=E[(f(x(1))โˆ’f(x0))2]โŸโ‰ฅ0+ฯƒ2โ‰ฅฯƒ2\text{EPE}_{\text{1-NN}} = \underbrace{\mathbb{E}[(f(x_{(1)}) - f(x_0))^2]}_{\geq 0} + \sigma^2 \geq \sigma^2

The ratio is: EPE1-NNEPEOLSโ‰ฅฯƒ2ฯƒ2=1\frac{\text{EPE}_{\text{1-NN}}}{\text{EPE}_{\text{OLS}}} \geq \frac{\sigma^2}{\sigma^2} = 1

But more precisely, even in p=1p=1 with nn points uniform on [0,1][0,1], the expected distance to the nearest neighbor is โˆผ1/(n+1)\sim 1/(n+1), giving a nonzero bias term. For the linear f(x)=x1f(x) = x_1, the distance contribution is small but positive, and the variance alone is already ฯƒ2\sigma^2. Since 1-NN uses a single noisy observation (variance =ฯƒ2= \sigma^2) while OLS averages over nn points (variance โ†’0\to 0), we get:

EPE1-NNEPEOLSโ‰ˆ0+ฯƒ2+ฯƒ2ฯƒ2=2\frac{\text{EPE}_{\text{1-NN}}}{\text{EPE}_{\text{OLS}}} \approx \frac{0 + \sigma^2 + \sigma^2}{\sigma^2} = 2

The key insight: 1-NN's irreducible ฯƒ2\sigma^2 variance (from the training label noise) is an extra cost OLS doesn't pay, because OLS borrows strength from all nn observations, while 1-NN only uses one.

As pp increases, the bias term E[(f(x(1))โˆ’f(x0))2]\mathbb{E}[(f(x_{(1)}) - f(x_0))^2] grows (nearest neighbor drifts away), so the ratio exceeds 2 and keeps growing โ€” exactly as shown in Figure 2.9 of ESL.

Source: The Elements of Statistical Learning, Hastie, Tibshirani, Friedman (2nd ed.), Section 2.5, Figure 2.9

Type: ML/StatsSource: The Elements of Statistical Learning, Hastie, Tibshirani, Friedman (2nd ed.), Section 2.5, Figure 2.9Edit on GitHub โ†—