Cross-Validation
Context: FIT2086_MOC · the resampling alternative to information criteria · generalises the single train/test split of Plug-in Prediction and Held-Out Evaluation · picks in Penalized Regression (Ridge and Lasso), in trees, in k-Nearest Neighbours · sibling resampling methods with different jobs ➔ Bootstrap (variability), Permutation Tests (-values)
Quick Revision
- 🎯 Objective: estimate a model’s prediction error on future data from the fitting data alone ➔ fit on part, score on the held-out rest, repeat, average ➔ choose the complexity with the smallest CV error.
- ⚠️ Key Constraint: every score must come from data the fit never saw; the cost is one fit per fold, so CV is slow when fitting is expensive.
📝 Core
- Target quantity ➔ ideally pick the model minimising error on future data : ➔ needs the test data in advance, which we never have.
- Key idea ➔ the fitting data came from the same process as future data ⟹ estimate the MSPE from itself.
- Procedure ➔ (1) randomly partition into and ; (2) fit to ; (3) compute its MSPE on ; (4) repeat and average ➔ run for every candidate model, keep the smallest.
- Complexity parameter (W9) ➔ write the candidates as ➔ = number of predictors (linear/logistic) · (ridge/lasso) · number of leaves (trees) · , distance and kernel (kNN) ➔ one CV recipe sizes them all.
- -fold CV ➔ split into equal-sized, disjoint random folds ; for fit to every fold except , predict , accumulate errors ➔ ➔ .
- Repeated -fold CV ➔ outer loop reruns the whole -fold procedure with new random partitions ➔ average scores; larger ⟹ more stable estimate (but slower).
- Leave-one-out (LOO) CV ➔ train on samples, test on the remaining one, for all held-out samples ⟹ fits ➔ the lecture’s tuner for kNN, where “fitting” is free.
- Any score works ➔ squared error, accuracy, or log-loss (Logarithmic Loss) can be the per-fold score.
- LOO ↔ AIC ➔ asymptotically related, but they can differ substantially for small samples.
- Worked selection ➔ Model 1 fold errors (mean ) vs Model 2 (mean ) ⟹ choose Model 2.
- Refit at the end ➔ CV only chooses ; the final model is refitted with on all the data (final tree with leaves, final lasso at ).
⚖️ Core Decision Matrix
| Variant | Fits required | Stability of the estimate | Reach for it when |
|---|---|---|---|
| -fold | depends on the one random partition | default — good balance of bias and variance | |
| Repeated -fold | improves as grows | the -fold estimate moves between reruns | |
| LOO | can be unstable | is small, or each fit is cheap (kNN has no fit at all) |
When It Flips: LOO's cost grows with while -fold's is fixed at ➔ as fitting gets expensive or grows, -fold wins.
⚠️ Common Mistakes
- 💡 Scoring on the training folds ➔ in-sample error always favours the most complex model — the exact failure CV exists to avoid.
- 💡 Choosing on a single random split ➔ one partition is noisy; average over folds (and repeats).
- 💡 Comparing models on different partitions ➔ use the same partitioning rule across the fits being compared so differences reflect the models, not the splits (
foldidin glmnet).
🧠 Active Recall
Why can CV estimate prediction error on future data without ever seeing future data?
Answer
- Short answer: The held-out fold plays the role of future data — it comes from the same process and was not used in the fit.
- Why: Same generating process ➔ held-out MSPE estimates the future-data ; averaging over folds (and repeats) makes that estimate more stable.
When would you prefer LOO over 5-fold CV, and what does it cost?
Answer
- Short answer: When is small, so leaving out a fifth of the data wastes too much; the cost is fits and an estimate that can be unstable.
- Why: Fits scale with ➔ LOO needs fits versus for -fold.
Name the complexity parameter that CV tunes for subset regression, ridge/lasso, a tree, and kNN.
Answer
- Short answer: number of predictors · · number of leaves · (plus distance and kernel).
- Why: One recipe ➔ each is a dial from simple to complex; , then refit on all the data.