Regularization Theory
Regularization restricts model complexity to prevent overfitting. It penalizes large model weights during training, forcing parameters to stay small.
Regularized Linear Regression Models
Three common regularized versions of linear regression modify the MSE cost function:
1. Ridge Regression (L2 Regularization)
Ridge Regression adds a penalty equal to the sum of squared weights to the cost function:
The hyperparameter controls regularization strength. If , it behaves like Ordinary Least Squares. Note that the bias term is not regularized.
2. Lasso Regression (L1 Regularization)
Lasso adds a penalty equal to the sum of absolute weights:
Lasso regression performs feature selection by forcing less important feature weights to exactly .
Geometric Intuition
L1 forms a diamond constraint boundary that tends to intersect coordinate axes at their corners, yielding sparse weights. L2 forms a spherical boundary, shrinking weights toward zero without setting them exactly to zero.
3. Elastic Net
Elastic Net combines Ridge and Lasso regularizations, controlled by a mix ratio :
It acts as a compromise, stabilizing selection when features are highly correlated.
Example: Parameter Sparsity
The following example demonstrates how Lasso regularizes weights to zero compared to Ridge:
Interactive Lab
Fit Ridge (L2) and Lasso (L1) regression estimators on a small dataset. Notice how Lasso sets weights exactly to zero while Ridge shrinks them close to zero.
Exercise
Test your understanding of regularized cost functions:
Under what scenario is Elastic Net preferred over Lasso regression?
Early Stopping
Early stopping is a regularization technique where validation error is monitored during iterative training. We stop training as soon as the validation error reaches a minimum and starts to increase.