2.6.15 · D5Model Evaluation & Selection
Question bank — Cross-validation pitfalls and nested CV
Before the questions, some notation we will lean on constantly:
True or false — justify
The parent selects , then reports as the model's score.
Standard CV gives an unbiased estimate of a single fixed model's error.
True — for one model chosen in advance, the K held-out folds are genuinely independent of training, so the average is honest. The bias only appears once you select among many models using those same scores.
The bias in comes from training on the validation folds.
False — you never trained on them. The bias comes from choosing because it won on those specific folds; selection, not training, is the leak.
Taking the minimum over CV scores makes the reported number smaller than the true average error.
True — the minimum of the noisy scores sits below their mean, so is negatively biased as an error estimate; the more configs , the larger the dip.
Nested CV removes bias by having the outer test folds never influence which hyperparameter is picked.
True — each outer test set is set aside before the inner loop tunes, so no decision ever touched it, making the outer average an honest estimate of the whole pipeline.
The inner-CV score is a valid performance estimate as long as you ran the outer loop correctly.
False — the inner score is optimistic by construction (it's a min over configs). It is only for picking ; performance is the outer average.
If two hyperparameters give identical inner-CV scores, nested CV becomes unnecessary.
False — a tie does not undo selection bias. You still have to pick one config using the same folds that would then grade it, and the reported score is still over all configs — the winning value is low partly because it got lucky on those folds. A single tie changes nothing about the search-wide optimism that nested CV exists to price in.
Nested CV's outer average tells you the best single hyperparameter to ship to production.
False — different outer folds may pick different . The outer average estimates pipeline performance; to ship, you retune on all data (or use the most-frequent ), separately from the estimate.
Bigger datasets make the standard-CV optimism worse.
False — larger data means lower-variance scores, so the "lucky minimum" wins by less; the optimism shrinks. Small data is where standard CV lies most.
Spot the error
You select the top-10 features by correlation with on the full dataset, then run 10-fold CV and report 92%.
The feature-selection step saw the validation folds, so the chosen features are tuned to noise in those very folds — this is leakage; feature selection must live inside each outer training split.
You normalize using the mean and standard deviation of the entire dataset before doing CV.
The scaler learned statistics from the held-out folds, leaking their distribution into training. Fit the scaler on the training portion only, inside the loop, and apply it to the held-out fold.
You run nested CV, then report the best inner-CV score as your final number.
You cherry-picked an optimistic, selection-biased score from one fold's tuning. Report the outer fold average instead — that's the number no decision contaminated.
You do nested CV but use the same inner folds for every outer fold by fixing the random seed globally on the whole dataset.
The inner folds would then include outer-test samples for some outer folds, re-leaking the test data into tuning. Inner splits must be drawn within each outer training set only.
You tuned 200 configurations, kept the best CV score, and called it "held-out performance."
With the min-over-configs bias is large; that score is a lower bound on error, not an estimate. You measured "best of 200 lucky draws," not generalization.
You did early stopping on your CV validation folds, then reported the CV error as final.
Early stopping is a decision made from validation performance, so those folds are no longer independent — the reported error is optimistic just like hyperparameter tuning.
You report the variance of the outer-fold errors as your model's uncertainty and treat the folds as independent samples.
Outer folds share overlapping training data, so their errors are correlated; the naive variance underestimates true uncertainty — treat the spread as a rough guide, not a clean standard error.
Why questions
Why is training-set K-fold CV for a single model fine, but reporting the tuned CV score dishonest?
The single-model score never involved a choice; the tuned score is the winner of a competition judged on the same folds, so it reflects both skill and luck on those folds.
Why does the optimism grow with the number of hyperparameters searched?
Each of the configurations is another independent chance to fluke a low on these particular folds, and the minimum of more noisy numbers drifts further below the mean.
Why does nested CV estimate the pipeline, not just the model?
Because each outer fold reruns the entire recipe — feature selection, tuning, fitting — from scratch on its own training data, so the outer error reflects everything the recipe would do on genuinely new data.
Why can Cawley & Talbot's example fall from 91% (standard) to 73% (nested)?
With 1000 features and 100 samples, many features correlate with by pure chance; standard CV selected those on the same data it validated on, fitting noise, while nested CV exposes that the noise doesn't transfer.
Why is "I held it out, so I didn't cheat" a false comfort?
Not training on data is only half of independence — every decision (features, , stopping) informed by that data spends its independence, even without a single gradient step on it.
Why does nested CV cost roughly times a single fit?
Each of the outer folds runs a full inner CV (which itself trains models per config), so the total number of model fits multiplies across both loops.
Why is the honest-but-worse nested number preferable to the flattering standard one?
A truthful 73% lets you set correct expectations and make sound deployment decisions; a fake 91% invites failure in production and destroys trust when reality bites.
Edge cases
With only one hyperparameter value (no search at all), is standard CV biased?
No — with there is no selection and no minimum to exploit, so plain CV is an honest estimate; the pitfall requires an actual choice among configs.
If your inner loop picks the same in every outer fold, is nested CV redundant?
No — a stable choice is reassuring but the outer folds still provide the unbiased performance estimate; consistency of tells you tuning is robust, not that you can skip the outer loop.
What is the smallest sensible dataset for nested CV, and what breaks first?
As a rule of thumb you want each outer test fold to hold at least ~10–20 samples and each inner fold likewise, so with 5×5 nesting you already need on the order of 100+ samples; below ~50 the inner folds shrink to a handful of points, tuning picks essentially at random, and the outer estimate — while still unbiased — becomes too noisy to trust. Under a few dozen samples, prefer repeated CV or a Bayesian/hold-out alternative.
Leave-one-out as the outer loop — does that eliminate bias?
It removes selection bias (each single point was never used to tune its own prediction), but LOO's outer errors are highly correlated and high-variance, so the estimate is unbiased yet unstable.
If preprocessing has no learned parameters (e.g., applied elementwise), must it still go inside the loop?
No — a fixed, data-independent transform learns nothing from any fold, so there is nothing to leak; only steps that fit on data (scaling, imputation, feature selection) must live inside.
Data is time-ordered (a time series) — does nested random K-fold fix the pitfall?
No — random folds let future rows train models tested on the past, a different leak; you need forward-chaining (time-respecting) splits in both loops, with the same never-touch-the-test rule.
Classes are severely imbalanced — does nested CV still give an honest number?
Yes, if you stratify both loops so each fold keeps the class ratio; without stratification a fold may miss a rare class, wrecking both tuning and the estimate regardless of the nesting.
Recall One-sentence summary
Standard CV becomes optimistic the moment a validation number drives a decision; nested CV restores honesty by keeping an outer test set that no decision — tuning, feature selection, or stopping — ever touched.