Overfitting, Underfitting & Regularization
A rigorous treatment of model complexity control: why overparameterized models memorize, how regularization constrains the hypothesis class, Tikhonov regularization as MAP estimation, and the double descent phenomenon.
Prerequisites
Table of Contents
- Learning Objectives
- Notation
- Core Intuition
- The Overfitting Phenomenon
- Regularized Risk Minimization
- Tikhonov (L2) Regularization
- L1 Regularization and Sparsity
- Elastic Net
- Bayesian Interpretation of Regularization
- Early Stopping as Implicit Regularization
- Double Descent and Modern Interpolation
- Common Pitfalls
- Summary
- Exercises
Learning Objectives
- Formally define overfitting and underfitting in terms of the generalization gap.
- Derive the ridge regression (L2) solution in closed form and interpret its spectral shrinkage.
- Derive the L1 penalty and explain why it induces sparsity via subgradient geometry.
- Show that L2 regularization is equivalent to MAP estimation with a Gaussian prior.
- Explain early stopping as implicit L2 regularization in gradient descent.
- Describe the double descent curve and reconcile it with classical bias-variance theory.
Notation
- — empirical risk, — population risk
- — regularization strength
- — regularizer (penalty functional)
- — squared L2 norm
- — L1 norm
- — design matrix (rows are samples)
- — target vector
Core Intuition
A model that is too simple (few parameters, restricted ) cannot capture the underlying pattern — this is underfitting. A model that is too complex can memorize noise in the training data — this is overfitting. Regularization adds a penalty for complexity, effectively constraining the search to "simpler" solutions within .
Regularization Path
The Overfitting Phenomenon
Definition. A model overfits if:
i.e., the training error is much smaller than the test error. The generalization gap is:
For a polynomial of degree fitting points: if , the polynomial interpolates perfectly () but oscillates wildly between points, yielding large .
Regularized Risk Minimization
Instead of pure ERM, we solve:
where penalizes complexity and controls the tradeoff.
Tikhonov (L2) Regularization
For linear models with squared loss:
Closed-form solution. Setting the gradient to zero:
Spectral interpretation. Let (SVD). Then:
The factor shrinks each component toward zero. Small singular values (noise directions) are shrunk most aggressively.
Effect on bias-variance:
- Increases bias (moves solution away from OLS).
- Decreases variance (stabilizes against noise in ).
- Optimal minimizes their sum.
L1 Regularization and Sparsity
No closed-form solution exists; solved via coordinate descent or proximal methods.
Why sparsity? The L1 ball has corners on coordinate axes. The ellipsoidal contours of the quadratic loss are most likely to first touch the constraint at a corner, setting some exactly.
Soft-thresholding. For orthogonal design (), the solution has the explicit form:
Elastic Net
Combines L1 and L2:
Benefits: sparsity from L1, grouping effect from L2 (correlated features get similar weights).
Bayesian Interpretation of Regularization
Theorem. L2 regularization MAP estimation with Gaussian prior.
Proof. Let and . The MAP estimate is:
Setting recovers ridge regression.
Corollary. L1 regularization corresponds to a Laplace prior: .
Early Stopping as Implicit Regularization
Consider gradient descent on the unregularized objective starting from :
Proposition (Ali et al., 2019). For squared loss with step size , after iterations:
This is equivalent to ridge regression with . Stopping early larger implicit more regularization.
Double Descent and Modern Interpolation
Classical theory predicts: as model complexity increases past the interpolation threshold (), test error explodes. But modern observations show:
Explanation. In the overparameterized regime, gradient descent selects the minimum-norm interpolant (see Gradient Flow). This implicit bias toward simplicity acts as regularization, even though training loss is zero.
Common Pitfalls
Pitfall 1. Regularizing the bias term. Typically the intercept should not be penalized — it shifts predictions but doesn't add complexity.
Pitfall 2. Not standardizing features before applying L1/L2. The penalty treats all coordinates equally; if features are on different scales, regularization acts unevenly.
Pitfall 3. Treating as a fixed hyperparameter. It should be tuned via cross-validation; the optimal depends on noise level, sample size, and feature correlation.
Summary
- Overfitting = large generalization gap; underfitting = high training error.
- L2 regularization shrinks coefficients spectrally; equivalent to Gaussian prior MAP.
- L1 regularization induces sparsity via corner geometry; equivalent to Laplace prior MAP.
- Early stopping implicitly regularizes with strength .
- Double descent reconciles interpolation with good generalization in overparameterized models.
Exercises
Exercise 1. Derive the ridge regression solution (equation 5) by differentiating the objective and setting to zero.
Exercise 2. Show that as , , and as , .
Exercise 3. For a diagonal design matrix , compute the ridge estimator's bias and variance for each coordinate.
Exercise 4. Prove that the Lasso solution for orthogonal design is the soft-thresholding operator (equation 8).
Exercise 5. Show that gradient descent with step size for steps on quadratic loss is equivalent to ridge with in the limit of small .