Skip to content
Machine Learning

What is the difference between L1 (Lasso) and L2 (Ridge) regularization?

L1 (lasso) adds the sum of the weights' absolute values to the loss and drives some weights exactly to zero. L2 (ridge, also called weight decay) adds the sum of their squares and shrinks every weight without zeroing any.

datasciencetrivia.com

Card 1 of 263. Answer: L1 (lasso) adds the sum of the weights' absolute values to the loss and drives some weights exactly to zero. L2 (ridge, also called weight decay) adds the sum of their squares and shrinks every weight without zeroing any.

Created by santiviquez

About · Quizzes · History of AI · To suggest new questions or report an error send me a dm.

The longer answer

L1 regularization, called lasso (least absolute shrinkage and selection operator), adds λ Σ |wᵢ|, λ times the L1 norm of the weights, to the loss. L2 regularization, called ridge after ridge regression, adds λ Σ wᵢ², λ times the squared Euclidean norm; neural networks call it weight decay and numerical analysis calls it Tikhonov regularization. Arthur Hoerl and Robert Kennard introduced ridge regression in 1970, and Robert Tibshirani introduced the lasso in 1996. The practical difference: L1 sets some weights exactly to zero, selecting features, while L2 shrinks every weight but keeps them all.

The penalties charge weights differently. For weights (4, 0.2), L1 charges 4.2 and L2 charges 16 + 0.04 = 16.04. Under L2 the small weight costs almost nothing, so nothing pushes it out, and the large weight dominates the penalty. Under L1 every unit of weight costs the same, so if a feature barely reduces the error, zeroing its weight is cheaper. Put another way, the L1 penalty pushes with a constant force λ all the way to zero, while the L2 push, 2λw, fades as w shrinks, so weights get small but stay nonzero.

With orthonormal features and the loss ½ ‖y − Xw‖², both have closed forms that make this concrete. Lasso shrinks each least-squares coefficient β̂ by λ and clips it at zero, ŵ = sign(β̂) · max(|β̂| − λ, 0): with λ = 0.5, coefficients 3.0, 0.4 and −1.2 become 2.5, 0 and −0.7. Ridge divides each one by 1 + 2λ instead, so the same coefficients become 1.5, 0.2 and −0.6: smaller, but none of them zero.

They also treat correlated features differently. If a feature appears twice and the fit needs the two weights to add up to 2, least squares can't choose between (2, 0) and (102, −100), which fit equally well. Ridge, minimizing ‖y − Xw‖² + λ Σ wᵢ², picks the equal split, a little under 1 each, because that has the smallest penalty; its closed form, ŵ = (XᵀX + λI)⁻¹ Xᵀy, adds λ to the diagonal so the matrix stays invertible. Lasso charges every same-sign split 2 and tends to keep one copy arbitrarily, which is why elastic net mixes both penalties. Because |w| has a kink at zero, lasso has no closed form in general; solvers use coordinate descent, as scikit-learn's Lasso does, or proximal steps.

In practice, standardize the features first. The penalty charges raw weight size, so a distance measured in kilometers instead of meters needs a weight 1,000 times larger and pays far more for it. Leave the intercept unpenalized and choose λ by cross-validation. Weight decay and L2 are the same under plain SGD but not under Adam, which is why AdamW applies the decay separately. In Bayesian terms, L1 is the MAP estimate under a Laplace prior and L2 under a Gaussian. And don't confuse them with L1 and L2 losses, mean absolute and mean squared error, which measure prediction error, not weight size.

All questions