Regularization
A technique to prevent overfitting in machine learning models
What Is Overfitting?
Overfitting happens when a model learns the training data too closely, including its noise and random
quirks, instead of learning the true underlying pattern. Such a model performs very well on training data but
poorly on new, unseen data.
What Is Regularization?
Regularization is a technique that discourages a model from becoming overly complex. It works by adding
an extra penalty to the model's error calculation, based on the size of the model's parameters (the internal
values the model learns). This penalty forces the model to keep its parameters small, resulting in a simpler
model that is less likely to chase noise and more likely to generalize well to new data.
How It Works (Step by Step)
1. Normally, a model tries to minimize prediction error alone.
2. Regularization adds a second term: a penalty based on parameter size.
3. The model now must balance two goals: fitting the data well, and keeping parameters small.
4. This balance prevents the model from relying too heavily on any single feature.
Two Main Types
Type Penalty Based On Effect
L1 (Lasso) Absolute value of Can shrink some parameters to exactly zero
parameters — removes unimportant features
automatically
L2 (Ridge) Squared value of Shrinks all parameters smaller, but rarely to
parameters exactly zero — reduces influence without
elimination
Bottom Line
Regularization trades a small increase in training error for a large improvement in how well the model
generalizes to new, unseen data. It is one of the primary tools used to control overfitting in machine learning
models.