The Cross-Validation That Peeked: Screening Before the Folds
You have a binary classification problem with samples and features. The data are pure noise:
- Labels are i.i.d. uniform on .
- Features are i.i.d. and independent of the labels.
An analyst runs Procedure W:
- Using all 50 samples, compute the sample correlation between each feature and the label. Keep the 100 features with the largest .
- Using only these 100 features, estimate the error of a 1-nearest-neighbour classifier with 5-fold cross-validation.
A colleague runs Procedure R: inside each CV fold, redo step 1 using only the training folds. Then fit 1-NN on the training folds and evaluate on the held-out fold.
Questions.
(a) What is the true test error of any classifier on this problem?
(b) Prove that the CV error estimate of Procedure R has expectation exactly .
(c) Procedure W typically reports an error of only a few percent. Explain why, and give a back-of-the-envelope reason the effect is so large.
(d) Suppose instead that, before cross-validation, the analyst keeps the 100 features with the largest sample variance across all 50 samples. Does this pre-screening bias the CV estimate?
Answer: The Cross-Validation That Peeked: Screening Before the Folds
Key Idea / Intuition
Cross-validation is honest only if the held-out labels play no role in building the model that predicts them. In Procedure W, the screening step already looked at every label, including the ones later "held out." It chose features that happen to line up with those labels. So the held-out points are not fresh: their labels are partly encoded in the selected features themselves. With 5000 candidate features, there are always 100 that line up remarkably well by chance, and averaging over 100 such weak alignments produces a strong fake signal. Screening that never looks at the labels, such as screening by variance, is harmless.
Formal Proof / Solution
(a) True error is
Since is independent of and , any classifier satisfies No method can beat a coin flip, so the Bayes error is .
(b) Procedure R is exactly unbiased
Fix a fold and a held-out index . In Procedure R, the prediction is a deterministic function of:
- the training data , which drives both the screening and the 1-NN fit, and
- the held-out feature vector .
By assumption, is independent of all of these. Write for the collection of these inputs. Then The CV estimate is the average of the indicators over all . By linearity of expectation, its expectation is exactly .
The argument uses nothing about 1-NN, the number of features, or the number of folds. It needs only one thing: the held-out label was never touched.
(c) Why Procedure W reports a tiny error
Where the logic breaks. In W, the selected feature set depends on all of . So the prediction depends on through , and the argument in (b) collapses.
How big the effect is. Under the null, the sample correlation of a feature with the labels is approximately . Keeping the top 100 of 5000 means keeping the top in absolute value. That corresponds to , so The average over the selected features is a bit larger. A typical value is .
What this means for the data. Let be the standardized label vector. For each selected feature, decompose the 50-vector as This decomposition holds on all 50 coordinates, including the samples later held out, because the correlation was computed on all of them. Each selected coordinate therefore carries a shift of about that depends on the class.
Effect on nearest-neighbour distances. In the 100-dimensional selected space:
- Same-class pairs have squared distance .
- Opposite-class pairs have an extra , giving about .
- The fluctuation of a squared distance is roughly .
So opposite-class points sit about two standard deviations farther away. Taking the minimum over about 20 candidates of each class makes the nearest neighbour usually same-class.
The result is a reported error of a few percent. Hastie–Tibshirani–Friedman's simulation of exactly this setup gives an average CV error of about , while the truth is .
The moral. Each selected feature is only a weak, chance alignment with the labels, about correlation. But the selection picked 100 of them out of 5000, and they all point at the same label vector. Summing 100 weak alignments yields a strong fake signal, and the fake signal includes the "test" points.
(d) Variance screening is fine
Sample variances are functions of the features only. Let denote everything used to produce : all 50 feature vectors (used for screening), plus the training labels. Then is still independent of , and the argument of (b) applies verbatim, giving expectation .
General rule: unsupervised preprocessing (variance filters, PCA on , standardization) may be done before CV. Any step that uses the labels must be repeated inside every fold.
Source: Hastie, Tibshirani & Friedman, The Elements of Statistical Learning (2nd ed.), Section 7.10.2 'The Wrong and Right Way to Do Cross-validation'