The Overfitting Problem
Need for Regularization
Read aloud is unavailable in this browser.
The Necessary Medicine for Overfitting
We've diagnosed the disease. We've traced its cause. Now we need the cure.
Overfitting manifests as a gap between training and test performance. High dimensionality creates the conditions for it to flourish. Variance explosion is the mechanism by which it destroys generalization.
The cure is regularization—a family of techniques that constrain the model to prevent it from fitting noise. But regularization isn't merely a technical trick. It represents a fundamental shift in how we think about learning: from finding the parameters that best fit the data to finding the parameters that are most likely to generalize.
This page makes the complete case for why regularization is not optional in modern machine learning—it's essential.
By the end of this page, you will understand the conceptual foundations of regularization from multiple perspectives: mathematical, statistical, Bayesian, and information-theoretic. You'll see why regularization is uniquely suited to solve the overfitting problem and preview the specific techniques covered in subsequent modules.
The Three Problems Regularization Solves
Regularization simultaneously addresses the three problems we've identified:
Problem 1: The Generalization Gap
Training error underestimates test error. The gap grows with model complexity. Regularization constrains complexity, directly reducing the gap.
Mathematically, generalization bounds have the form:
$$\text{Test Error} \leq \text{Train Error} + \text{Complexity Penalty}$$
Regularization adds an explicit complexity penalty to the objective, trading off training fit against model simplicity:
$$\hat{\beta} = \arg\min_\beta \left[ \text{Loss}(\beta) + \lambda \cdot \text{Complexity}(\beta) \right]$$
Problem 2: Ill-Posed Optimization in High Dimensions
When $p > n$, OLS has infinitely many solutions. Regularization makes the problem well-posed by introducing a unique optimal solution.
The regularized objective:
$$\hat{\beta}{ridge} = \arg\min\beta |y - X\beta|^2 + \lambda|\beta|^2$$
is strictly convex for any $\lambda > 0$, guaranteeing a unique global minimum regardless of whether $X^T X$ is invertible.
Problem 3: Variance Explosion
Small eigenvalues of $X^T X$ cause coefficient variance to explode. Regularization stabilizes the solution by preventing the inverse from amplifying noise.
Ridge regularization replaces $(X^T X)^{-1}$ with $(X^T X + \lambda I)^{-1}$, ensuring all eigenvalues are at least $\lambda$. The condition number becomes:
$$\kappa_{ridge} = \frac{\lambda_{max} + \lambda}{\lambda_{min} + \lambda} \ll \frac{\lambda_{max}}{\lambda_{min}}$$
The worse the original conditioning, the more improvement regularization provides.
| Problem | OLS Behavior | Regularization Effect |
|---|---|---|
| Generalization gap | Grows with p | Bounded by λ penalty |
| Multiple solutions (p > n) | Infinite solutions | Unique solution |
| Variance explosion | Var ∝ 1/λ_min | Var ≤ 1/λ |
| Coefficient magnitude | Unbounded, large | Shrunk toward zero |
| Sensitivity to noise | High | Dampened |
Regularization as Constrained Optimization
One powerful way to understand regularization is through constrained optimization. Instead of minimizing training loss subject to no constraints, we minimize subject to a budget on model complexity.
The Constraint View
Ridge regression can be equivalently written as:
$$\hat{\beta}{ridge} = \arg\min\beta |y - X\beta|^2 \quad \text{subject to} \quad |\beta|^2 \leq t$$
We minimize training loss, but only among solutions whose coefficient norm is bounded.
Intuition: We don't trust the full OLS solution because it overfits. By constraining $|\beta|^2 \leq t$, we force the model to find a solution that fits the data while remaining simple enough to generalize.
The Lagrangian dual of this problem gives the penalized form:
$$\hat{\beta}{ridge} = \arg\min\beta \left[ |y - X\beta|^2 + \lambda |\beta|^2 \right]$$
where $\lambda$ is the Lagrange multiplier corresponding to the constraint. Larger $\lambda$ corresponds to tighter constraint $t$.
Imagine the OLS solution as a point in high-dimensional space. Ridge regression finds the point on the sphere ||β||² ≤ t that is closest to the OLS solution (in the sense of minimizing training loss). Lasso uses a diamond (L1 ball) instead of a sphere, leading to sparse solutions.
Why This Works
The constraint $|\beta|^2 \leq t$ embodies a prior belief: true coefficients are probably not huge.
This is often reasonable:
- In standardized data, coefficients represent effect sizes per standard deviation
- Effect sizes larger than ~10 are rare in most domains
- Huge coefficients usually indicate fitting noise, not signal
The constraint excludes the pathological OLS solutions where coefficients explode to $\pm 1000$ to exactly interpolate noise.
Regularization as Bayesian Prior
From a Bayesian perspective, regularization corresponds to placing a prior distribution on the parameters. This provides deep theoretical justification for regularization techniques.
The Bayesian Framework
In Bayesian inference, we combine:
- Likelihood $P(y | \beta, X)$: probability of data given parameters
- Prior $P(\beta)$: our beliefs about parameters before seeing data
to get:
- Posterior $P(\beta | y, X) \propto P(y | \beta, X) \cdot P(\beta)$
The Maximum A Posteriori (MAP) estimate finds the most probable parameters:
$$\hat{\beta}{MAP} = \arg\max\beta \log P(y | \beta, X) + \log P(\beta)$$
Ridge = Gaussian Prior
If we assume Gaussian noise and a Gaussian prior on coefficients:
$$y | \beta \sim N(X\beta, \sigma^2 I)$$ $$\beta \sim N(0, \tau^2 I)$$
The log-posterior (ignoring constants) is:
$$\log P(\beta | y, X) \propto -\frac{1}{2\sigma^2}|y - X\beta|^2 - \frac{1}{2\tau^2}|\beta|^2$$
Maximizing this is equivalent to Ridge regression with $\lambda = \sigma^2/\tau^2$.
Interpretation: The prior says "I believe coefficients are small, normally distributed around zero." The smaller $\tau^2$, the more concentrated the prior, the stronger the regularization.
Lasso = Laplace Prior
If instead we use a Laplace (double exponential) prior:
$$P(\beta_j) \propto \exp(-|\beta_j| / b)$$
The MAP estimate becomes:
$$\hat{\beta}{MAP} = \arg\min\beta \left[ |y - X\beta|^2 + \lambda \sum_j |\beta_j| \right]$$
This is exactly L1 regularization (Lasso). The Laplace prior has heavier tails than Gaussian but more mass at zero, encouraging sparsity.
| Regularization | Prior Distribution | Property Encouraged |
|---|---|---|
| Ridge (L2) | Gaussian: $β \sim N(0, τ²I)$ | Small coefficients |
| Lasso (L1) | Laplace: $P(β) ∝ e^{-|β|/b}$ | Sparse coefficients |
| Elastic Net | Mixture of Gaussian + Laplace | Small and sparse |
| Horseshoe | Heavy-tailed spike-and-slab | Extreme sparsity |
| Group penalties | Structured priors | Grouped selection |
In high-dimensional settings, the prior dominates the posterior for many coefficients because there isn't enough data to overwhelm it. This is exactly what we want: when data is limited, we lean on prior knowledge (coefficients are probably small) rather than fitting noise.
Regularization as Generalization Control
Statistical learning theory provides formal guarantees connecting regularization to generalization.
Structural Risk Minimization (SRM)
The Structural Risk Minimization principle (Vapnik) defines a sequence of hypothesis classes $\mathcal{H}_1 \subset \mathcal{H}_2 \subset \ldots$ of increasing complexity. For each class, we have a generalization bound:
$$R(h) \leq R_{emp}(h) + \Phi(\mathcal{H}_k, n, \delta)$$
where $\Phi$ grows with complexity and shrinks with sample size. SRM selects the class that minimizes the bound, not just empirical risk.
Regularization implements SRM implicitly: the penalty $\lambda|\beta|^2$ corresponds to restricting the complexity, with $\lambda$ selecting effectively among the nested classes.
Rademacher Complexity Bounds
For ridge regression with constraint $|\beta|_2 \leq B$, the Rademacher complexity is:
$$\mathcal{R}_n(\mathcal{H}_B) \leq \frac{BL}{\sqrt{n}}$$
where $L$ is a bound on feature norms. This directly gives:
$$\text{Test Error} \leq \text{Train Error} + O\left(\frac{B}{\sqrt{n}}\right)$$
Smaller $B$ (stronger regularization) → tighter bound → better generalization guarantee.
The Bias-Variance Trade-off Formalized
For ridge regression, the expected test error decomposes as:
$$\text{MSE}(\lambda) = \text{Bias}^2(\lambda) + \text{Variance}(\lambda) + \sigma^2$$
Both terms depend on $\lambda$:
| λ | Bias² | Variance | Total Error |
|---|---|---|---|
| 0 (OLS) | 0 | High | High (variance dominated) |
| Small | Low | Moderate | Lower |
| Optimal | Medium | Medium | Minimum |
| Large | High | Low | Higher (bias dominated) |
| ∞ | = Var(y) | 0 | High (null model) |
The optimal $\lambda$ balances bias and variance to minimize total error.
Plotting test error against λ produces a U-shape. Too little regularization (left) causes variance explosion. Too much (right) causes underfitting. Cross-validation finds the minimum.
The Information-Theoretic Perspective
Information theory provides yet another lens on regularization, connecting it to the principle of Occam's Razor.
Minimum Description Length (MDL)
The MDL principle states that the best model is one that provides the shortest description of the data. This description has two parts:
$$L(D) = L(M) + L(D | M)$$
- $L(M)$: Length of describing the model
- $L(D|M)$: Length of describing the data given the model (residuals)
A complex model (large $L(M)$) can describe data with small residuals (small $L(D|M)$), but the total length may be longer than a simpler model with slightly larger residuals.
Regularization implements MDL: the penalty $\lambda|\beta|^2$ approximates the description length of the parameter vector.
Occam's Razor, Formalized
"Do not multiply entities beyond necessity."
Regularization formalizes Occam's Razor: among hypotheses that explain the data similarly well, prefer the simpler one.
- OLS minimizes training error regardless of complexity
- Regularized regression minimizes training error plus a complexity penalty
The penalty quantifies "necessity"—how much complexity is justified by the improvement in fit.
Connection to AIC/BIC
Information criteria like AIC and BIC can be seen as regularization:
$$\text{AIC} = n \log(\hat{\sigma}^2) + 2p$$ $$\text{BIC} = n \log(\hat{\sigma}^2) + p \log(n)$$
Both add penalties proportional to $p$ (number of parameters). This implicitly regularizes model selection, though explicit regularization like Ridge/Lasso is often more effective in high dimensions.
That regularization emerges from constraint optimization, Bayesian inference, statistical learning theory, AND information theory is remarkable. These independent perspectives all converge on the same techniques—strong evidence that regularization is fundamental, not merely a convenient trick.
When is Regularization Necessary?
Regularization is not always essential. Understanding when it's critical vs. optional guides practical decisions.
Regularization is ESSENTIAL when:
- •p > n (more features than samples): Without regularization, infinitely many solutions exist. Regularization is required to define the problem.
- •p ≈ n (features close to samples): Classical OLS becomes unstable. Near-singular matrices cause variance explosion.
- •Features are highly correlated: Multicollinearity makes coefficient allocation arbitrary without regularization.
- •Limited training data: Small samples mean high variance; regularization injects prior information.
- •Signal-to-noise ratio is low: When noise dominates, unregularized methods fit noise rather than signal.
Regularization is HELPFUL but optional when:
- •n >> p (many more samples than features): Classical regression works, but light regularization often still improves generalization.
- •Features are carefully selected: Domain expertise has already eliminated irrelevant features.
- •Interpretability matters: Regularized coefficients (especially Ridge) may be harder to interpret than OLS.
- •Prediction is less important than inference: Statistical inference (confidence intervals, p-values) is more developed for OLS.
| Scenario | p/n | Regularization | Reasoning |
|---|---|---|---|
| Genomics study | 200 | Essential | p >> n, underdetermined |
| Image classification | 1000+ | Essential | Massively high-dimensional |
| Survey with 10 questions, 1000 responses | 0.01 | Optional | n >> p, classical works |
| Clinical trial, 20 variables, 200 patients | 0.1 | Recommended | Moderate p/n |
| Time series, 5 lags, 10000 points | 0.0005 | Light regularization | Very low p/n |
Preview of Regularization Techniques
This module establishes why regularization is necessary. The subsequent modules in this chapter cover how specific techniques work.
Module 2: Ridge Regression (L2 Regularization)
$$\hat{\beta}{ridge} = \arg\min\beta |y - X\beta|^2 + \lambda |\beta|_2^2$$
- Shrinks all coefficients toward zero
- Closed-form solution: $(X^T X + \lambda I)^{-1} X^T y$
- Handles multicollinearity beautifully
- All features retained, none exactly zero
Module 3: Lasso Regression (L1 Regularization)
$$\hat{\beta}{lasso} = \arg\min\beta |y - X\beta|^2 + \lambda |\beta|_1$$
- Induces sparsity: some coefficients become exactly zero
- Performs feature selection automatically
- No closed-form solution; requires iterative algorithms
- Can select at most $n$ features when $p > n$
Module 4: Elastic Net
$$\hat{\beta}{elastic} = \arg\min\beta |y - X\beta|^2 + \lambda_1 |\beta|_1 + \lambda_2 |\beta|_2^2$$
- Combines L1 and L2 penalties
- Sparsity from L1 + stability from L2
- Better handles correlated features than pure Lasso
- Two hyperparameters to tune
Module 5: Bayesian Interpretation
- Full posterior inference, not just point estimates
- Uncertainty quantification through posterior distributions
- Automatic regularization strength selection
- Hierarchical models for grouped structure
Module 6: Advanced Regularization
- Group Lasso for feature groups
- Fused Lasso for spatial/temporal smoothness
- Non-convex penalties for better sparsity
- Structured regularization for domain knowledge
KEEP LEARNING
There’s more to understand.
You’re reading the introduction. Create a free account to read the complete lesson, save notes and keep track of your progress.