A colleague standardises all features using the mean and standard deviation of the entire dataset, selects the 20 features most correlated with the label y, 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 y; every learned preprocessing and feature-selection step must sit strictly inside each training fold.

Steps

  1. Answer directly: no, the CV accuracy is optimistically biased due to data leakage from the validation folds into preprocessing.
  2. 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 y directly into which predictors enter the model.
  3. Illustrate how severe full-dataset screening is (Hastie–Tibshirani–Friedman): suppose n=50 examples have p=5000 pure noise features independent of random binary labels y∈{0,1}, so the true error rate of any classifier is 50%. Screening all 5000 features on the full 50 rows picks 20 features that happened by chance to correlate strongly with those 50 labels — including the validation folds — yielding a fake CV error far below 50% (often under 5%).
  4. Show the correct pipeline: split into folds first; inside each fold k, fit the scaler (mean, std) *and* run the correlation feature selector using only the 4 training folds, transform the k-th validation fold with that fitted pipeline, and score the classifier.

Common mistakes

How long your answer should be

Half a page; 4–5 minutes.

Last checked on 4 December 2026.

Read this

Previous in Foundations: Let X,Z∼N(0,Id) be two independent d-dimensional standard Gaussian vectors. Compute E[∥X−Z∥22] and SD⁡(∥X−Z∥22) as functions of d. Why does the ratio SD⁡(∥X−Z∥22)/E[∥X−Z∥22] tend to 0 as d→∞, and how does this break distance-based methods like k-NN?
Next in Foundations: When data are missing at random (MAR), suppose an outcome Y is observed only when R=1, where the observation probability π(X)=P(R=1∣X,Y)=P(R=1∣X)>0 depends only on fully observed covariates X. Why is the unweighted complete-case sample mean biased for E[Y], and how do you prove that the inverse-probability-weighted (IPW) estimator μ^IPW=1n∑i=1nRiYiπ(Xi) is unbiased?