Why does reporting the best validation score from k-fold hyperparameter tuning give an optimistically biased error estimate, how does nested cross-validation fix this, and how many total model fits are required for 5 outer folds, 4 inner folds and 6 hyperparameter candidates?

ML systems and evaluation, Cross-validation
Level L3 Intermediate. Length Medium. Nature Th+Mat Both.

What's being asked

Whether you understand model-selection optimism ("winner’s curse") and can trace and cost a nested CV loop.

Key idea

Selecting the best hyperparameter setting by its k-fold score picks whichever candidate got luckiest on those folds; nested CV isolates an untouched outer test fold to evaluate the entire tuning procedure, requiring Kout(Kin⋅G+1) model fits for Kout outer folds, Kin inner folds and G hyperparameter candidates.

Steps

  1. Explain selection bias: evaluating G candidates on the same k folds and reporting max⁡gscore(g) has positive bias (the winner’s curse), because random fold noise helps whichever candidate overfits the validation folds.
  2. Describe the outer and inner loops: split data into Kout=5 outer folds; inside each outer training split (4/5 of the data), run Kin=4-fold inner CV across all G=6 candidates to pick the best setting, refit that winner on the outer training split, and score it on the unseen outer fold.
  3. Count the fits: each outer fold runs 4×6=24 inner fits plus 1 outer refit =25 fits, so 5 outer folds require 5×25=125 model fits.
  4. Note final deployment: nested CV produces an unbiased estimate of the tuning pipeline’s generalisation performance, not a single deployable model—to ship one model, run one final 5-fold CV on all data (5×6+1=31 more fits) to pick the final model.

Common mistakes

How long your answer should be

4–5 sentences plus the fit arithmetic; 3–4 minutes.

Last checked on 4 December 2026.

Read this

Previous in ML systems and evaluation: A student standardises features and applies PCA on the full dataset before running 5-fold cross-validation, obtaining 92% accuracy, whereas fitting both inside each fold yields 81%. Why does the first setup leak information, how does a pipeline fix it, and why is supervised feature selection before CV even more damaging?
Next in ML systems and evaluation: On four binary outcomes y=[1,0,1,0], Forecaster A predicts p^A=[0.8,0.2,0.8,0.2] and Forecaster B predicts p^B=[1.0,0.5,0.5,0.0]. What are their Brier scores, and how do you prove that the Brier score is a strictly proper scoring rule?