A colleague standardises all features using the mean and standard deviation of the entire dataset, selects the 20 features most correlated with the label , and then runs 5-fold cross-validation to tune and report the accuracy of a classifier. Is the resulting CV accuracy unbiased, how do you fix the pipeline, and how badly can full-dataset feature screening distort pure random noise?
Foundations, Feature engineering
Level L3 Intermediate. Length Medium. Nature Th+Mat Both.
What's being asked
Whether you can spot pre-CV preprocessing and feature-selection leakage in a pipeline and explain both the fix and the severity of label-based leakage.
Key idea
The CV score is optimistically biased because validation folds influenced the scaling statistics and, far more severely, helped choose the 20 features using their labels ; every learned preprocessing and feature-selection step must sit strictly inside each training fold.
Steps
- Answer directly: no, the CV accuracy is optimistically biased due to data leakage from the validation folds into preprocessing.
- Compare the two leaks: global standardisation leaks distribution statistics () of held-out folds (usually a modest bias for i.i.d. data, though fatal if a validation outlier shifts or ), whereas supervised feature screening on the full dataset leaks the held-out labels directly into which predictors enter the model.
- Illustrate how severe full-dataset screening is (Hastie–Tibshirani–Friedman): suppose examples have pure noise features independent of random binary labels , so the true error rate of any classifier is . Screening all features on the full rows picks features that happened by chance to correlate strongly with those labels — including the validation folds — yielding a fake CV error far below (often under ).
- Show the correct pipeline: split into folds first; inside each fold , fit the scaler (mean, std) *and* run the correlation feature selector using only the training folds, transform the -th validation fold with that fitted pipeline, and score the classifier.
Common mistakes
- Saying global scaling before CV is "completely fine" because it does not touch : while much milder than label-based feature selection, it still breaks held-out independence (especially with imputation, PCA, or min-max scaling).
- Running `SelectKBest` outside `Pipeline` before calling `cross_val_score` in scikit-learn — a textbook coding bug.
How long your answer should be
Half a page; 4–5 minutes.
Last checked on 4 December 2026.
Read this
Previous in Foundations: Let be two independent -dimensional standard Gaussian vectors. Compute and as functions of . Why does the ratio tend to as , and how does this break distance-based methods like -NN?
Next in Foundations: When data are missing at random (MAR), suppose an outcome is observed only when , where the observation probability depends only on fully observed covariates . Why is the unweighted complete-case sample mean biased for , and how do you prove that the inverse-probability-weighted (IPW) estimator is unbiased?