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

VariantFits requiredStability of the estimateReach for it when
-folddepends on the one random partitiondefault — good balance of bias and variance
Repeated -foldimproves as growsthe -fold estimate moves between reruns
LOOcan 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 (foldid in glmnet).

🧠 Active Recall