Search Knowledge

© 2026 LIBREUNI PROJECT

Machine Learning / Supervised Learning

Regularization Theory

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:

J(θ)=MSE(θ)+α12i=1nθi2J(\theta) = \text{MSE}(\theta) + \alpha \frac{1}{2} \sum_{i=1}^{n} \theta_i^2

The hyperparameter α\alpha controls regularization strength. If α=0\alpha = 0, it behaves like Ordinary Least Squares. Note that the bias term θ0\theta_0 is not regularized.

2. Lasso Regression (L1 Regularization)

Lasso adds a penalty equal to the sum of absolute weights:

J(θ)=MSE(θ)+αi=1nθiJ(\theta) = \text{MSE}(\theta) + \alpha \sum_{i=1}^{n} |\theta_i|

Lasso regression performs feature selection by forcing less important feature weights to exactly 00.

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 rr:

J(θ)=MSE(θ)+rαi=1nθi+(1r)α12i=1nθi2J(\theta) = \text{MSE}(\theta) + r \alpha \sum_{i=1}^{n} |\theta_i| + (1 - r) \alpha \frac{1}{2} \sum_{i=1}^{n} \theta_i^2

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:

python

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.

Step 1
Inspect the idea
Step 2
Edit the program
Step 3
Run and compare

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.

References & Further Reading

Previous Module Logistic Regression
Next Module Naive Bayes