Skip to content
IT glossary
Data and MLUpdated December 3, 2026

Regularization

Регуляризация

Regularization changes how a model learns so it is less likely to fit noise in the training data and more likely to work on new examples. L1 and L2 do this by penalizing large model coefficients.

Also known as: L1, L2

Why regularize a model?

A model can fit its training data closely and still make poor predictions on new examples. That happens when it learns quirks of the sample rather than patterns that hold elsewhere. This is called overfitting. Regularization trades some flexibility during training for a chance at better performance on unseen data. A higher training error can be a good trade if validation error goes down.

What L1 and L2 change

Instead of minimizing prediction loss alone, training minimizes data loss + λ × penalty. The penalty depends on the model's coefficients, and the hyperparameter λ controls how much it matters relative to the data loss. A value of zero removes the penalty. In standard linear models, the intercept is usually left unpenalized.

  • L1 adds up the absolute values of the coefficients: Σ |wᵢ|. It can set some coefficients to exactly zero, effectively dropping those features from a linear prediction. Linear regression with an L1 penalty is called lasso.
  • L2 adds up the squared coefficients: Σ wᵢ². Doubling a coefficient quadruples its contribution to the penalty. L2 typically shrinks coefficients toward zero without making them exactly zero. Linear regression with an L2 penalty is called ridge regression.

L1 and L2 are two forms of regularization, not alternate names for the whole idea. Early stopping, for instance, limits how long a model trains rather than adding a coefficient penalty to the objective.

Example: nearly duplicate predictors

Suppose a model predicts monthly electricity use from two temperature sensors in the same room. An unregularized linear model might give one reading a large positive coefficient and the other a large negative one. The two effects mostly cancel, but the model can use tiny differences between the sensors to fit noise. L2 makes that pair of large coefficients expensive, so ridge is often a useful starting point when predictors are strongly correlated. L1 might drop one sensor entirely, but which one it drops can change when you retrain on a different sample.

Choosing a strength without leaking data

With penalized linear models, continuous features are often standardized before fitting. A coefficient for distance in meters is numerically smaller than the equivalent coefficient for distance in kilometers, even though the predictions are identical. Without scaling, those equivalent effects incur different penalties. When using cross-validation, fit the scaler on the training portion of each fold, then reuse it to transform that fold's validation data.

Compare several penalty strengths using validation data or cross-validation and keep the test set for a final estimate. Too little regularization may leave overfitting in place; too much can make the model underfit. Check the library's parameter convention before tuning: some APIs expose an inverse strength, so a larger value means a weaker penalty.

What interviewers look for

Go beyond saying that L1 selects features and L2 shrinks weights. Explain why L1 can land exactly at zero, and say how you would test whether either penalty improves performance on new data.