Skip to main content

What do L1 and L2 regularisation do?

Machine learning basics · Intermediate 1

Short answer

Both add a penalty on the size of the model's weights to the loss, which discourages overfitting. L2 (ridge) penalises squared weights and shrinks them all smoothly towards zero. L1 (lasso) penalises absolute weights and pushes many to exactly zero, so it also selects features. The strength is a hyperparameter you tune on validation data.

Deeper answer

Without a penalty, a model with many features can give large weights to noise. Regularisation trades a little training error for simpler weights that generalise better.

Use L2 when many features each carry a little signal, and L1 when you suspect only a few matter and want a sparse, explainable model. Elastic net mixes both and behaves better when features are correlated, where lasso tends to pick one at random. Scale features first, because the penalty treats all weights alike. In neural networks, L2 appears as weight decay, alongside other regularisers such as dropout.

What a strong answer covers

Answer it out loud in the mock interview about 1 min

Follow-ups to expect

Common mistakes

Learn it

Regression

Today's AI turns are used

Lessons, roadmaps, videos, practice cards and the code playground stay free with your account, with no limit.