Foundations to Frontier
Tests

Overfitting, Underfitting and Model Capacity

A model can fail by being too simple to capture the pattern (underfitting) or by being flexible enough to memorize the noise (overfitting). This topic covers capacity and how it is controlled (parameters, degree, regularization, early stopping), training vs test error, learning curves, validation and k-fold cross-validation, information criteria, and the modern twist: over-parameterized models can interpolate the training data and still generalize, producing 'double descent'. In the research exercise you reproduce the classic U-curve and cross-validation, then show double descent with random-feature regression, where test error spikes when the model barely fits the data and falls again beyond it.

Level 0: Foundation

★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.

Memorizing vs understanding

A student who memorizes last year’s exam answers scores perfectly on that exam but fails a new one. That’s overfitting: learning the quirks of the examples instead of the pattern. A student who learns only one rule of thumb does badly on both: that’s underfitting. Capacity is how much a model can memorize: more parameters, more wiggle room. The trick is matching capacity to how much data you have.

Capacity: from underfitting to overfitting
1e-31e-21e-11e01e1degree →MSE (log): blue train, orange test
degree 3: training error 0.0578 · test error 0.1154 · best degree on this sample: 3 · noise floor σ² = 0.0625
Low degrees can't bend enough: both errors are high (underfitting). As capacity grows, training error keeps dropping (each extra coefficient can only help fit the same points), but past the sweet spot test error climbs as the curve chases noise (overfitting). Drag the number of points up and the overfitting region moves right: more data supports more capacity.
Why engineers care

A terrain classifier that’s perfect on its training images but fails on a new crater field, or a dynamics model that fits test-flight data exactly but predicts nonsense outside it, are overfitting failures. Validation discipline (held-out data, cross-validation, early stopping) is what separates a demo from a deployable system.

📝 Quick check (Level 0)
0/3 answered
  1. 1. Perfect training accuracy but poor accuracy on new data means…
  2. 2. A model too simple for the pattern…
  3. 3. More training data generally lets you use…

Level 1: Beginner

★★☆☆☆ Basic⏱ 25 minSecondary-school mathematics: arithmetic and elementary algebra.

Training vs test error

Training error measures fit to the examples; test error on fresh data estimates the true risk (b1-1).

  • As capacity grows, training error only falls: a richer model can always fit at least as well.
  • Test error falls, then rises. This classic U-shape mirrors the bias–variance trade-off (b1-3).
  • Generalization gap = test error − training error.

Controlling capacity

  • Explicitly: number of parameters, polynomial degree, tree depth, k in k-NN.
  • Implicitly: regularization penalties (ridge, lasso, weight decay), early stopping, dropout, data augmentation.

Learning curves

Plot training and test error against n for a fixed model. Training error rises and test error falls until both approach the noise floor. If they plateau high together, the model is underfitting: add capacity. A persistent gap means overfitting: add data or regularize.

📝 Quick check (Level 1)
0/3 answered
  1. 1. As polynomial degree increases, training error…
  2. 2. Learning curves with a large persistent gap suggest…
  3. 3. Early stopping is a form of…

Level 2: Intermediate

★★★☆☆ Intermediate⏱ 40 minUndergraduate students and practising engineers.

Validation and cross-validation

Never choose capacity using test data. Hold out a validation set, or use k-fold cross-validation: split into k folds, train on k − 1, evaluate on the held-out fold, and average. Choose the capacity with the lowest CV error, then retrain on all the data. Small datasets favour k = 5–10; leave-one-out has low bias but high variance.

Information criteria

For likelihood models, AIC = 2k − 2 ln L̂ and BIC = k ln n − 2 ln L̂ trade fit against parameter count k without a held-out set (a5-2-5). For Gaussian regression, AIC ∝ n ln(RSS/n) + 2k.

Double descent

Modern networks often have more parameters than data points and fit the training data exactly, yet generalize. Belkin, Hsu, Ma and Mandal (2019) observed that test error can follow a double descent:

  1. the classic U up to the interpolation threshold (parameters ≈ data points), where the model barely manages to fit everything, highly unstably;
  2. a second descent as capacity grows further, because among the many interpolating solutions, gradient descent and least squares pick a minimum-norm, “smooth” one.

Regularization smooths away the spike (Hastie et al., 2022; Nakkiran et al., 2021).

🐍 Exercise 1: the U-curve, cross-validation and learning curves
Fit polynomials of degree 0–15 to small training sets. Show that training error is monotone, that the median test error is U-shaped, that 5-fold CV picks a near-optimal degree from training data alone, and that learning curves converge to the noise level.
📝 Quick check (Level 2)
0/3 answered
  1. 1. Why not choose the degree with the lowest test error?
  2. 2. The interpolation threshold is where…
  3. 3. Beyond the threshold, least squares (pseudo-inverse) returns…

Level 3: Advanced

★★★★☆ Advanced⏱ 40 minGraduate level, with full derivations and proofs.

Why training error is monotone

The degree-d polynomials are a subset of the degree-(d + 1) polynomials (set the top coefficient to 0). So the minimum training error over the larger class is no bigger. ∎

Why the threshold is dangerous

At p = n the feature matrix F is square, typically with tiny singular values smin⁡s_{\min}. The fitted coefficients F−1yF^{-1}y amplify noise by 1/smin⁡1/s_{\min}. With p much larger than n, the minimum-norm solution F+yF^+y only uses the large singular directions, and the effective noise amplification falls again. Ridge adds λ to the squared singular values (it divides by s + λ/s instead of s), capping the amplification. ∎ (Hastie et al., 2022, make this exact for random features.)

Model selection by AIC

AIC estimates out-of-sample log-likelihood: the 2k penalty corrects the optimism of the in-sample fit, to first order (Akaike, 1974).

📝 Quick check (Level 3)
0/3 answered
  1. 1. Training error is monotone in degree because…
  2. 2. At the interpolation threshold, noise is amplified by about…
  3. 3. Ridge regularization fixes the spike by…

Level 4: Expert

★★★★★ Expert⏱ 35 minResearchers: original papers and open problems.

Classic and modern generalization curves

The U-curve. With 25 points of y = sin 2πx + x/2 + noise (σ² = 0.0625), the median test MSE over 20 training sets is 0.436 at degree 0, 0.077 at degree 3 (best), 0.227 at degree 9 and 1.9 at degree 13. On one dataset, 5-fold CV picks degree 5, whose test MSE is 0.077 against the best possible 0.068. Degree-7 learning curves (train/test): 0.016/4.91 at n = 10, 0.042/0.092 at n = 30, 0.061/0.068 at n = 100 and 0.062/0.064 at n = 1000, converging to the noise.

Double descent. Random-ReLU-feature regression with n = 100 samples. Median test MSE of the minimum-norm least-squares fit against the number of features p:

p 10 40 80 100 120 300 1000
test MSE 1.18 1.27 3.45 189 4.04 1.55 1.27

At p = 100 the training error is exactly zero, and the fit is wildly unstable. A ridge penalty of 0.01 removes the spike: test MSE 1.23, 1.70 and 1.17 at p = 40, 100 and 1000. Here the second descent recovers to about the level of the best small model; with richer targets and inductive biases (deep networks) it can go well below it.

🐍 Exercise 2 (research): double descent
Fit random-ReLU-feature regressions with p features on n = 100 samples using the pseudo-inverse (minimum-norm least squares). Sweep p across the interpolation threshold, show zero training error beyond it, the test-error spike at p ≈ n and the second descent, and check that a small ridge penalty removes the spike.

Capacity in AI, robotics and aerospace

  • Practice: train/validation/test splits; cross-validation for small datasets; early stopping on validation loss; data augmentation for vision.
  • Deep learning: over-parameterized networks interpolate and still generalize; implicit regularization of SGD (B4).
  • System identification: model-order selection for dynamics models (AIC, validation on separate flights).
  • Safety: monitoring for out-of-distribution inputs where an overfit model is most dangerous.

References

  1. T. Hastie, R. Tibshirani, J. Friedman (2009). The Elements of Statistical Learning, 2nd ed. Springer.
  2. M. Belkin, D. Hsu, S. Ma, S. Mandal (2019). “Reconciling modern machine-learning practice and the classical bias–variance trade-off.” PNAS, 116.
  3. P. Nakkiran, G. Kaplun, Y. Bansal, T. Yang, B. Barak, I. Sutskever (2021). “Deep double descent: where bigger models and more data hurt.” J. Stat. Mech. (ICLR 2020).
  4. T. Hastie, A. Montanari, S. Rosset, R. Tibshirani (2022). “Surprises in high-dimensional ridgeless least squares interpolation.” Annals of Statistics, 50.
  5. H. Akaike (1974). “A new look at the statistical model identification.” IEEE TAC, 19.