Skip to content

Regularization

Any technique that discourages a model from becoming too complex, so it generalizes better to new data.

Also L1 · L2 · weight decay

Domain 01
Foundations
Role · kind
TrainingTechnique
Level
Intermediate

It is like a word limit on an essay. You cannot ramble about every tiny detail, so you have to focus on what really matters.

Where it fits

+All relationships as a list

See it on the full map

How it works

Overfitting happens when a model uses its flexibility to memorize noise. Regularization takes some of that flexibility away.

The classic way is to add a penalty on the size of the weights to the loss. Now the model has two goals: fit the data, and keep the weights small. Large weights are only worth it if they really help.

  • L2 (ridge, weight decay) penalizes squared weights. It shrinks everything a little and spreads importance across correlated features.
  • L1 (lasso) penalizes absolute weights. It tends to set unimportant weights to exactly zero, giving a simpler model.

Other techniques do the same job differently: dropout randomly disables neurons during training, early stopping halts training before memorization sets in, and data augmentation creates new varied training examples.

The mathLreg(w)=Ldata(w)+λ ∥w∥22(L2)Lreg(w)=Ldata(w)+λ ∥w∥1(L1)L_{\text{reg}}(w) = L_{\text{data}}(w) + \lambda \, \|w\|_2^2 \quad \text{(L2)} \qquad L_{\text{reg}}(w) = L_{\text{data}}(w) + \lambda \, \|w\|_1 \quad \text{(L1)}

The hyperparameter λ\lambda sets how strongly complexity is punished.

Everyday use cases

  • Case 01

    Predicting with many features

    Lasso picks out the handful of useful features among hundreds of candidates in a marketing dataset.

  • Case 02

    Training neural networks

    Weight decay is on by default in most modern training recipes, including for large language models.

Strengths, weaknesses and when to use it

Strengths

  • Cheap and simple to add.
  • L1 doubles as automatic feature selection.

Weaknesses

  • The penalty strength is another hyperparameter to tune.
  • Too much regularization causes underfitting.

When to use itWhenever a model has many parameters relative to the amount of training data.

Compare with

Check yourself

  1. Q01

    What does L1 regularization tend to do to weights?

    Show answer

    B: Push many of them to exactly zero

Go deeper

Learn first