Bias–Variance Trade-off and Cross-Validation
Underfitting and overfitting, the bias–variance decomposition of expected squared error, how model complexity, regularisation and data size move bias and variance, learning curves, and estimating generalisation error — hold-out validation, k-fold cross-validation, leave-one-out cross-validation, stratification, nested CV, and avoiding data leakage.
Underfitting and overfitting
| Underfitting | Good fit | Overfitting | |
|---|---|---|---|
| Training error | high | low | very low |
| Test error | high | low | high |
| Gap | small | small | large |
| Cause | model too simple / too regularised | — | model too flexible for the data, fits noise |
The bias–variance decomposition
Suppose with , , and is learned from a random training set. At a point :
- Bias: error from wrong assumptions — how far the average model is from the truth.
- Variance: how much the model changes with the training sample.
- Irreducible error: noise no model can remove.
What moves bias and variance
| Change | Bias | Variance |
|---|---|---|
| More flexible model (higher polynomial degree, deeper tree, smaller in k-NN, larger / in SVM) | ↓ | ↑ |
| Stronger regularisation (larger ) | ↑ | ↓ |
| More training data | ≈ | ↓ |
| More features | ↓ | ↑ |
| Bagging / averaging models | ≈ | ↓ |
| Boosting | ↓ | (↑ if overdone) |
Learning curves (error vs training-set size) diagnose the problem: if training and validation errors converge at a high value, the model is biased (more data won't help); if a large gap remains, it has high variance (more data helps).
Estimating generalisation error
Hold-out validation
Split once into training and validation (e.g. 80/20). Cheap, but the estimate depends on the particular split and wastes data — risky for small data sets.
k-fold cross-validation
- Split the data into equal folds.
- For : train on the other folds, evaluate on fold .
- Average the validation errors: .
- or is the standard trade-off between bias (smaller training sets) and variance/computation.
- Stratified k-fold keeps class proportions equal across folds — important for imbalanced classification.
- Repeated CV with different shuffles reduces the variance of the estimate.
- For time series, use forward-chaining splits (train on the past, validate on the future), never random folds.
Leave-one-out cross-validation (LOOCV)
: train on points, test on the one left out, times.
| LOOCV | 5/10-fold CV | |
|---|---|---|
| Training-set size | (almost all) | – |
| Bias of the estimate | very low | slightly pessimistic |
| Variance of the estimate | can be high (folds nearly identical) | lower |
| Cost | fits (closed form for linear regression: ) | fits |
| Randomness | deterministic | depends on the split |
Using CV correctly
- Model selection: compute the CV error for each hyperparameter value (e.g. , , depth) and pick the best; then retrain on all the training data.
- Nested CV: an outer loop estimates performance while an inner loop tunes hyperparameters — otherwise the selected model's CV score is optimistically biased.
- The test set is used once, at the very end.
- No leakage: fit every preprocessing step (scaling, imputation, feature selection, oversampling) inside the training folds only.
Quick revision
Practice questions
GATE-style questions: 3 one-mark and 7 two-mark. Wrong MCQs cost ⅓ of their marks in the real exam; MSQ and NAT have no negative marking. Attempt each before opening the solution.
A model has high error on both the training set and the test set, with the two errors close to each other. The model is most likely
Which statements about the bias–variance trade-off are correct?
One or more options are correct.
In 5-fold cross-validation on a data set of 1000 examples, each model is trained on how many examples? ______
Leave-one-out cross-validation on a data set of 50 examples requires fitting the model ______ times.
Compared with 10-fold cross-validation, leave-one-out cross-validation gives an error estimate that is
At a test point, an estimator has bias 0.3 and variance 0.16, and the noise variance is 0.1. The expected squared prediction error there is ______.
Training accuracy is 99% but test accuracy is 70%. Which action is least likely to help?
5-fold cross-validation gives validation errors 0.10, 0.12, 0.08, 0.11 and 0.09. The cross-validation estimate of the error is ______.
Which procedure causes data leakage in cross-validation?
A 1-nearest-neighbour classifier is evaluated by leave-one-out cross-validation on four 1-D points: (A), (A), (B), (B). The LOOCV error rate is ______.