Model Assessment: Cross-Validation and Model Selection
Why training error lies, how cross-validation estimates out-of-sample error honestly, and how AIC/BIC and the one-standard-error rule pick complexity.
Leads to: CV is the tool that chooses \(\lambda\) in ridge/lasso (11.4) and every hyperparameter after.
Learning Objectives
Click a status chip to cycle: Not started → In progress → Studied → Practiced → Needs review → Mastered.
- Explain why training error is a downward-biased estimate of test error (optimism).
- Implement K-fold cross-validation and reason about the bias-variance tradeoff in choosing K.
- Compare AIC, BIC, and Mallows' Cp as analytic complexity penalties.
- Apply the one-standard-error rule to choose a parsimonious model.
- Diagnose how leakage and improper CV in finance inflate apparent performance.
Key Vocabulary
- Training error
- Average loss on the same data used to fit; optimistically low, decreasing with complexity.
- Test error
- Expected loss on independent data from the same distribution; the quantity we actually care about.
- Optimism
- The gap \(\E[\text{test}]-\E[\text{train}]\); grows with model complexity and with fitting noise.
- K-fold CV
- Split data into \(K\) folds; fit on \(K-1\), validate on the held-out fold, rotate, average.
- LOOCV
- Leave-one-out CV: \(K=n\); nearly unbiased but high variance and expensive.
- AIC / BIC
- Analytic scores balancing fit against parameter count; BIC penalizes complexity more heavily as \(n\) grows.
- One-standard-error rule
- Choose the simplest model whose CV error is within one standard error of the minimum.
Intuition & Motivation
Cross-validation is the honest exam. Hide part of the data, fit on the rest, grade on what was hidden, and rotate so every point gets a turn as the test. The averaged score estimates test error without needing a separate hold-out you cannot afford. In finance the catch is subtle: the data are ordered in time and serially dependent, so shuffling them lets the future leak into the past - a beautiful CV curve built on cheating.
Why training error is optimistic
Fit \(\hat f\) by minimizing loss on the training set. The same optimization that reduces error also fits the noise \(\varepsilon\) in those specific points. For squared loss the expected optimism is provably positive and proportional to how strongly fitted values co-move with the responses:
where the effective degrees of freedom \(\text{df}=\tfrac1{\sigma^2}\sum_i\Cov(\hat y_i,y_i)\) equals \(p\) for linear regression with \(p\) parameters and \(\tr(H)\) more generally. More flexibility means more optimism.
K-fold cross-validation
Partition the \(n\) rows into \(K\) roughly equal folds. For each fold \(k\), fit on the other \(K-1\) folds and record the loss on fold \(k\). The CV estimate is
where \(\kappa(i)\) is the fold containing point \(i\) and \(\hat f^{-\kappa(i)}\) is the model trained without that fold. Each point is predicted by a model that never saw it.
Analytic penalties: Cp, AIC, BIC
When refitting many times is costly, in-sample scores add an explicit complexity penalty to the training loss:
AIC targets predictive accuracy (asymptotically like LOOCV); BIC targets recovering the true model and, because its penalty \(p\log n\) grows with \(n\), selects more parsimonious models and is consistent for model identity. In finance, with weak signals and large \(n\), BIC's heavier penalty guards against spurious factors.
Interactive: K-fold CV picks polynomial degree
- Selecting features or standardizing using the whole dataset before splitting - the test folds then leak into training (see 11.7).
- Using random K-fold on time-series data; shuffling lets the future predict the past. Use forward-chaining.
- Picking the exact CV minimum and ignoring its uncertainty; the one-SE rule exists because that minimum is noisy.
- Comparing AIC across models fit on different data sets or with different responses - the likelihoods are not comparable.
- Running dozens of model variants and reporting only the best CV score - that is selection bias / backtest overfitting.
- Nest your CV: an outer loop estimates performance, an inner loop tunes hyperparameters, so tuning never sees the test fold.
- For time series always validate forward in time; a purged, embargoed split removes leakage from overlapping labels.
- Report the CV standard error, not just the mean; use the one-SE rule to prefer the simpler model.
- Count how many configurations you tried - the more you search, the more the winning score is inflated by luck.
Knowledge Check
Practical Exercise
You have 2000 daily returns and want to select the lag order \(p\) of a return-predicting regression. (a) Why is random K-fold inappropriate here? (b) Describe a leakage-free validation scheme. (c) You tried \(p=1,\dots,20\) and report the best CV Sharpe. What bias remains and how would you quantify it?
(a) Returns are time-ordered and serially/volatility dependent. Random folds put future observations in the training set used to predict past ones (look-ahead), and overlapping information across nearby days leaks across the split, inflating the score.
(b) Use forward-chaining / walk-forward CV: train on \([1,t]\), test on \([t+1,t+h]\), roll forward. Add a purge (drop training points whose label window overlaps the test) and an embargo (skip a gap after each test block) to kill leakage from autocorrelation.
(c) Selecting the best of 20 configurations is a maximum over noisy estimates - selection bias / backtest overfitting: the reported best CV Sharpe is upward biased. Quantify it by (i) a nested/outer test set never used for selection, (ii) a deflated Sharpe ratio that adjusts for the number of trials, or (iii) a permutation/bootstrap null to see how large a ‘best of 20’ Sharpe arises by chance.
Lesson Summary
Formula Sheet Additions
- Did I fit every preprocessing step inside the CV loop, not before it?
- For time series, did I validate forward with purge/embargo instead of shuffling?
- Did I use the one-SE rule rather than the raw CV minimum?
- Did I record how many configurations I searched and adjust for it?
Retrieval Practice
Close the lesson and answer from memory before checking. This is deliberate, effortful recall - the single highest-yield study action.
A: Optimism \(=2\sigma^2\text{df}/n\); for linear regression \(\text{df}=p\), so the gap is \(2p\sigma^2/n\).
A: Small K: pessimistic bias (smaller training sets) but low variance/cost. LOOCV: nearly unbiased but high variance from correlated near-identical fits.
A: Pick the simplest model within one SE of the minimum CV error, because that minimum is itself uncertain and parsimony generalizes better.
Flashcards
Click to flip. These feed the site-wide spaced-repetition queue.
Completion Checklist
- I can explain the core ideas in my own words
- I worked the derivations/examples by hand
- I completed the interactive workbench(es)
- I passed the knowledge check
Source References
This lesson synthesizes and paraphrases concepts from the sources below. No copyrighted text, problem sets, or solutions are reproduced. Return to the originals for full depth.
- The Elements of Statistical Learning (Hastie, Tibshirani & Friedman, 2nd ed.) current - ESL 7 - Ch. 7: model assessment and selection, optimism, cross-validation, AIC/BIC, effective df.
- Time Series Analysis (James Hamilton, 1994) foundational - Hamilton 4 - Lag-order selection and information criteria for time-series models.