Why Regularization Reduces Overfitting
Regularization reduces overfitting by constraining a model's effective hypothesis space so it cannot fit random noise in the training data with extreme weights. Shrinking weight magnitudes bounds the function's Lipschitz constant—making predictions smoother across neighboring inputs—and damps unstable directions associated with small singular values. In doing so, regularization accepts a modest bias increase in exchange for a much larger drop in variance, improving test generalization.
Study Card: Why Regularization Reduces Overfitting
Direct Answer
Regularization reduces overfitting by preventing a model from using overly large or overly numerous parameters to memorize training noise. Three mathematical perspectives explain why this improves generalization:
- Capacity / Hypothesis Space Constraint: Penalizing restricts optimization to a smaller ball of simpler functions, reducing the model’s variance (Rademacher complexity / effective degrees of freedom).
- Smoothness via Lipschitz Continuity: For linear models in feature space , Cauchy–Schwarz gives . Smaller bounds how sharply predictions can swing between nearby points, smoothing out spurious wiggles.
- Spectral / Collinearity Stabilization: In Ridge regression, writing shows each singular direction is shrunk by . Small singular values —which normally amplify label noise massively in —are damped aggressively when .
Key Terms
- Overfitting: Fitting noise and sampling quirks of training data, leading to high variance and poor test performance.
- Effective Degrees of Freedom: Measure of model flexibility (e.g., in Ridge) that decreases monotonically as grows.
- Lipschitz Smoothness: Bounding weight norms limits the maximum slope/oscillation rate of the learned function.
- Bias–Variance Tradeoff: Trading a slight increase in systematic bias for a large reduction in prediction variance.
Example
Suppose you fit a 10th-degree polynomial to noisy samples drawn from a simple quadratic curve . With tiny regularization (), adjacent polynomial terms take huge cancelling weights (e.g., ) to thread through individual noise points, oscillating violently on test data. Increasing Ridge regularization () shrinks those high-order weights, recovering the smooth underlying parabola with far lower test MSE.
Code Implementation
import numpy as np
import matplotlib.pyplot as plt
from sklearn.linear_model import Ridge
from sklearn.metrics import mean_squared_error
from sklearn.model_selection import train_test_split
from sklearn.pipeline import Pipeline
from sklearn.preprocessing import PolynomialFeatures, StandardScaler
# Generate noisy quadratic data
rng = np.random.default_rng(0)
X = 6 * rng.random((80, 1)) - 3
y = 0.5 * X[:, 0] ** 2 + X[:, 0] + 2.0 + rng.normal(0, 1.0, size=80)
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=42)
weak_reg = Pipeline([
("poly", PolynomialFeatures(degree=10, include_bias=False)),
("scaler", StandardScaler()),
("ridge", Ridge(alpha=1e-5)), # Very weak regularization -> overfits
])
stronger_reg = Pipeline([
("poly", PolynomialFeatures(degree=10, include_bias=False)),
("scaler", StandardScaler()),
("ridge", Ridge(alpha=1.0)), # Meaningful L2 regularization -> smoother fit
])
weak_reg.fit(X_train, y_train)
stronger_reg.fit(X_train, y_train)
for name, model in [("Weak Ridge (alpha=1e-5)", weak_reg), ("Stronger Ridge (alpha=1.0)", stronger_reg)]:
tr_mse = mean_squared_error(y_train, model.predict(X_train))
te_mse = mean_squared_error(y_test, model.predict(X_test))
w_norm = np.linalg.norm(model.named_steps["ridge"].coef_)
print(f"{name:28s} | Train MSE: {tr_mse:.3f} | Test MSE: {te_mse:.3f} | ||w||_2: {w_norm:.2f}")
X_plot = np.linspace(-3, 3, 200).reshape(-1, 1)
plt.figure(figsize=(9, 5))
plt.scatter(X_train, y_train, color="steelblue", s=22, label="Train")
plt.scatter(X_test, y_test, color="green", marker="^", s=30, label="Test")
plt.plot(X_plot, weak_reg.predict(X_plot), "g--", lw=2, label="Weak L2 (alpha=1e-5)")
plt.plot(X_plot, stronger_reg.predict(X_plot), "r-", lw=2, label="Regularized L2 (alpha=1.0)")
plt.ylim(-1, 12)
plt.xlabel("X")
plt.ylabel("y")
plt.title("How L2 Regularization Suppresses Polynomial Overfitting")
plt.legend()
plt.grid(True)
plt.show()
Related Concepts
- Bias–Variance Tradeoff: Explains why intermediate minimizes expected generalization error (note: modern overparameterized deep learning also benefits from implicit SGD regularization alongside explicit weight decay).
- L1 vs. L2 Regularization: L1 achieves simplicity via sparse feature selection; L2 achieves smoothness via dense shrinkage.
- Cross-Validation: Tunes regularization strength using held-out validation folds.
- Early Stopping & Dropout: Algorithmic regularization strategies that limit effective training capacity and prevent co-adaptation in neural networks.