๐Ÿงฎ Brain Teaser

The Bootstrap That Fools Itself: 1-Nearest Neighbor on Pure Noise

You have NN training points (xi,yi)(x_i, y_i), i=1,โ€ฆ,Ni=1,\dots,N. The xiโˆˆRpx_i \in \mathbb{R}^p are distinct, and the labels yiโˆˆ{0,1}y_i \in \{0,1\} are pure noise. Each label is an independent fair coin flip, independent of xx. The classifier is 1-nearest neighbor (1-NN). Its true test error is exactly 1/21/2.

To estimate the error you draw BB bootstrap samples. Each one consists of NN draws with replacement from the training set. Let f^โˆ—b\hat f^{*b} be the 1-NN classifier fit on bootstrap sample bb.

(a) Show that the probability that a fixed observation ii appears in a given bootstrap sample tends to 1โˆ’eโˆ’1โ‰ˆ0.6321 - e^{-1} \approx 0.632 as Nโ†’โˆžN \to \infty.

(b) The naive bootstrap error estimate tests every bootstrap model on the original training set:

Err^boot=1B1Nโˆ‘b=1Bโˆ‘i=1N1{f^โˆ—b(xi)โ‰ yi}.\widehat{\mathrm{Err}}_{\text{boot}} = \frac{1}{B}\frac{1}{N}\sum_{b=1}^{B}\sum_{i=1}^{N} \mathbf 1\{\hat f^{*b}(x_i) \neq y_i\}.

Compute its expected value as N,Bโ†’โˆžN, B \to \infty. Is it close to the true error 1/21/2?

(c) A natural fix is the leave-one-out bootstrap Err^(1)\widehat{\mathrm{Err}}^{(1)}. It scores observation ii only with bootstrap models whose sample does not contain ii. Efron's .632 estimator combines this with the training error errโ€พ\overline{\mathrm{err}}:

Err^(.632)=0.368โ€‰errโ€พ+0.632โ€‰Err^(1).\widehat{\mathrm{Err}}^{(.632)} = 0.368\,\overline{\mathrm{err}} + 0.632\,\widehat{\mathrm{Err}}^{(1)}.

What value does the .632 estimator give in this example? What does this tell you?

bootstraperror estimationnearest neighboroverfitting0.632 rule

Answer: The Bootstrap That Fools Itself: 1-NN on Pure Noise

Key Idea / Intuition

A bootstrap sample is a noisy copy of the training set. About 63% of the original points reappear in it, and 37% are left out.

1-NN memorizes perfectly. When a point is in the bootstrap sample, the model finds the point itself at distance 00 and predicts its label correctly, for free. Only the left-out points actually test the model, and on those it is a coin flip.

So the naive bootstrap reports an error of about 0.368ร—0.5โ‰ˆ0.180.368 \times 0.5 \approx 0.18, which is badly optimistic. The .632 correction blends in the training error, which is also 00 for 1-NN. That blend is itself fooled, giving 0.3160.316.

The moral: these estimators are fooled exactly when the model overfits as hard as possible. This failure is what motivates Efron's .632+ correction.


Formal Proof / Solution

(a) The 0.632 probability

A single draw misses observation ii with probability 1โˆ’1N1 - \tfrac1N. The NN draws are independent, so

Prโก(iโˆ‰sampleย b)=(1โˆ’1N)Nโ†’Nโ†’โˆžeโˆ’1โ‰ˆ0.368.\Pr(i \notin \text{sample } b) = \left(1-\frac1N\right)^N \xrightarrow{N\to\infty} e^{-1} \approx 0.368.

Hence

Prโก(iโˆˆsampleย b)โ†’1โˆ’eโˆ’1โ‰ˆ0.632.\Pr(i \in \text{sample } b) \to 1 - e^{-1} \approx 0.632.

Equivalently, a bootstrap sample contains only about 0.632N0.632N distinct points.

(b) The naive bootstrap is badly optimistic

Fix a pair (b,i)(b, i) and split into two cases.

Case 1: iโˆˆi \in sample bb. The point xix_i is in the bootstrap training set at distance 00 from itself. The xx's are distinct, so it is the unique nearest neighbor, and therefore f^โˆ—b(xi)=yi\hat f^{*b}(x_i) = y_i. The loss is 00.

Case 2: iโˆ‰i \notin sample bb. The prediction f^โˆ—b(xi)\hat f^{*b}(x_i) is the label of some other training point jโ‰ ij \neq i. Labels are independent fair coins, so yjy_j is independent of yiy_i. Therefore

Prโก(f^โˆ—b(xi)โ‰ yi)=12.\Pr\big(\hat f^{*b}(x_i) \neq y_i\big) = \tfrac12.

Combining the two cases:

E[Err^boot]=0โ‹…Prโก(iโˆˆb)+12Prโก(iโˆ‰b)=12(1โˆ’1N)Nโ€…โ€ŠโŸถโ€…โ€Š12eโˆ’1โ‰ˆ0.184.\mathbb E\big[\widehat{\mathrm{Err}}_{\text{boot}}\big] = 0\cdot \Pr(i\in b) + \tfrac12 \Pr(i\notin b) = \tfrac12\left(1-\tfrac1N\right)^N \;\longrightarrow\; \tfrac12 e^{-1} \approx 0.184.

This is far below the true error of 0.50.5. The cause is that the bootstrap "training" and "test" sets overlap by about 63%, exactly as in ordinary training error.

(c) The .632 estimator is still fooled

Leave-one-out bootstrap. For each ii we use only the models with iโˆ‰bi \notin b. That is always Case 2 above, so each term has expected loss 1/21/2:

Err^(1)โ‰ˆ0.5.\widehat{\mathrm{Err}}^{(1)} \approx 0.5.

This estimator is honest here. In general it is slightly pessimistic, because each model effectively trains on only about 0.632N0.632N distinct points.

Training error. 1-NN fit on the full data predicts each training point from itself, so

errโ€พ=0.\overline{\mathrm{err}} = 0.

The .632 blend. The weights 0.3680.368 and 0.6320.632 are meant to pull the pessimistic Err^(1)\widehat{\mathrm{Err}}^{(1)} toward the optimistic errโ€พ\overline{\mathrm{err}}. Here they give

Err^(.632)=0.368โ‹…0+0.632โ‹…0.5=0.316โ‰ 0.5.\widehat{\mathrm{Err}}^{(.632)} = 0.368\cdot 0 + 0.632\cdot 0.5 = 0.316 \neq 0.5.

Interpretation. The .632 rule implicitly assumes a moderate amount of overfitting. When the model memorizes completely (errโ€พ=0\overline{\mathrm{err}} = 0 regardless of signal), the blend drags the estimate down by a factor of 0.6320.632.

Remark: the .632+ repair. Efron and Tibshirani measure overfitting explicitly. Let ฮณ^\hat\gamma be the no-information error rate, the error when xx and yy are independent. Here ฮณ^=0.5\hat\gamma = 0.5. Define the relative overfitting rate

R^=Err^(1)โˆ’errโ€พฮณ^โˆ’errโ€พ=0.5โˆ’00.5โˆ’0=1.\hat R = \frac{\widehat{\mathrm{Err}}^{(1)} - \overline{\mathrm{err}}}{\hat\gamma - \overline{\mathrm{err}}} = \frac{0.5 - 0}{0.5 - 0} = 1.

The adaptive weight is then

w^=0.6321โˆ’0.368โ€‰R^=1.\hat w = \frac{0.632}{1 - 0.368\,\hat R} = 1.

So the .632+ estimator puts all its weight on Err^(1)\widehat{\mathrm{Err}}^{(1)}. It returns 0.50.5, which is correct.

Source: Hastie, Tibshirani, Friedman โ€” The Elements of Statistical Learning (2nd ed.), Section 7.11 (Bootstrap Methods)

Type: ML/StatsSource: Hastie, Tibshirani, Friedman โ€” The Elements of Statistical Learning (2nd ed.), Section 7.11 (Bootstrap Methods)Edit on GitHub โ†—