Skip to content
ML Visualization

Ridge vs Lasso Regression

Ridge regression shrinks every coefficient toward zero but keeps them all; lasso drives some coefficients exactly to zero, deleting features from the model entirely. Both add a penalty on coefficient size to ordinary least squares, trading a little bias for a large drop in variance, but the penalty shape differs: ridge uses the L2 penalty, the sum of squared coefficients, while lasso uses the L1 penalty, the sum of absolute values. The L1 penalty's sharp corners are what make exact zeros possible, so lasso does automatic feature selection and ridge does not.

That geometric difference drives the practical guidance. When many features each contribute a little, and especially when features are correlated, ridge tends to predict better because it spreads weight smoothly across the correlated group. When only a few features truly matter and the rest are noise, lasso tends to win because it can silence the noise features completely and hand you a sparse, readable model. Lasso's known weakness is correlated predictors: it tends to pick one from a group somewhat arbitrarily and zero the others, and the survivor can change with a slightly different sample.

Both methods share two non-negotiable mechanics. Features must be standardized first, because the penalty treats all coefficients on the same scale, so an unscaled feature measured in large units gets unfairly crushed. And the penalty strength, usually called alpha or lambda, must be chosen by cross-validation, since the best value depends entirely on your data's signal-to-noise ratio and sample size, and no fixed default works across problems.

Side by side

Core idea

Ridge Regression (L2)

Add the sum of squared coefficients to the least-squares loss, shrinking all weights smoothly toward zero.

Lasso Regression (L1)

Add the sum of absolute coefficient values to the loss, shrinking weights and setting the weakest ones exactly to zero.

Penalty type

Ridge Regression (L2)

L2 penalty; differentiable everywhere, with a closed-form solution available.

Lasso Regression (L1)

L1 penalty; non-differentiable at zero, which is precisely what produces exact zeros, solved by coordinate descent or similar methods.

Effect on coefficients

Ridge Regression (L2)

Proportional-style shrinkage: every coefficient gets smaller, none reach exactly zero, and correlated features share the weight.

Lasso Regression (L1)

Soft thresholding: small coefficients are cut to exactly zero while surviving ones are shrunk by a constant amount.

Feature selection

Ridge Regression (L2)

None; the final model always uses every feature, however tiny its weight.

Lasso Regression (L1)

Built in; the zeroed coefficients remove features, yielding a sparse model you can read and deploy cheaply.

Correlated features

Ridge Regression (L2)

Handles them gracefully by splitting weight across the correlated group, keeping predictions stable.

Lasso Regression (L1)

Handles them poorly; it tends to keep one member of a correlated group arbitrarily and zero the rest, and the choice is unstable across resamples.

When it shines

Ridge Regression (L2)

Dense problems where many features each carry a little signal, and prediction accuracy matters more than a short feature list.

Lasso Regression (L1)

Sparse problems where a few features carry most of the signal and the rest are noise, or when you need an interpretable short list.

Key hyperparameters

Ridge Regression (L2)

One penalty strength alpha, chosen by cross-validation; larger alpha means more shrinkage.

Lasso Regression (L1)

One penalty strength alpha, chosen by cross-validation; larger alpha zeros out more features.

Preprocessing requirements

Ridge Regression (L2)

Standardize features first; unscaled features distort how the penalty distributes shrinkage.

Lasso Regression (L1)

Same requirement, and it matters even more because scale directly decides which coefficients cross the zero threshold.

More features than samples

Ridge Regression (L2)

Works well; the penalty makes the ill-posed least-squares problem solvable and stable.

Lasso Regression (L1)

Works and additionally prunes the feature set, but can select at most as many features as there are samples.

Typical use cases

Ridge Regression (L2)

Multicollinear regression, dense signals such as many weak predictors, and as the default stabilizer for linear models.

Lasso Regression (L1)

High-dimensional screening such as genomics or text, model compression, and any setting where the deliverable is a short feature list.

When to use Ridge Regression (L2)

  • Your features are strongly correlated and you want stable coefficients and predictions rather than an arbitrary winner from each group.
  • You believe many features each contribute a small amount, so deleting any of them would discard real signal.
  • Prediction accuracy is the goal and nobody is asking you for a shortlist of variables.
  • You want the most forgiving default: ridge rarely does anything surprising, making it the safe first regularizer.
  • You need fast, closed-form or highly stable fits inside a larger pipeline, for example repeated refits in cross-validation.

When to use Lasso Regression (L1)

  • You suspect only a handful of your many features actually matter and want the model to find and name them.
  • Interpretability is a requirement: stakeholders need a short list of variables, not a hundred small weights.
  • You have far more features than samples and need aggressive pruning before anything downstream.
  • Deployment cost matters and dropping features saves real measurement or computation, such as removing sensors or expensive data fields.
  • You are doing exploratory screening to decide which features deserve deeper study, treating the selection as a hypothesis, not a verdict.

The bottom line

If you only care about predictions, start with ridge: it is stable, handles correlated features gracefully, and almost never behaves surprisingly. Choose lasso when sparsity is itself a goal, because you need a short interpretable feature list, or you have vastly more features than samples and must prune. If you want lasso's selection but your features come in correlated groups, skip the dilemma and use elastic net, which blends both penalties and keeps or drops correlated features together. Whichever you choose, standardize your features first and pick the penalty strength by cross-validation; those two steps matter more than the L1-versus-L2 decision in most real problems.

Frequently asked questions

Can I use ridge and lasso together?
Yes, that combination is elastic net. It mixes the L1 and L2 penalties with a mixing ratio you tune alongside the overall strength. You get lasso's ability to zero out features plus ridge's stability with correlated predictors, so correlated groups tend to enter or leave the model together instead of one arbitrary member surviving.
Why does lasso produce exact zeros but ridge does not?
Geometry. The L1 constraint region is a diamond with corners on the axes, and the loss surface tends to touch it at a corner, where some coefficients are exactly zero. The L2 region is a sphere with no corners, so the touching point almost never lands exactly on an axis; coefficients get small but stay nonzero.
Do I need to standardize features before ridge or lasso?
Yes, almost always. The penalty compares raw coefficient sizes, so a feature measured in small units needs a large coefficient and gets punished unfairly, while a feature in large units sneaks through. Standardizing to zero mean and unit variance puts all coefficients on a common scale. Most libraries do not do this for you automatically.
How do I choose the regularization strength alpha?
Cross-validation over a logarithmic grid of alpha values is the standard approach, and libraries provide it directly through tools like RidgeCV and LassoCV. There is no universally good default because the right strength depends on the signal-to-noise ratio and sample size. Plotting the coefficient paths against alpha is also a useful diagnostic.
Is lasso's feature selection trustworthy for finding the true important variables?
Treat it as a strong hint, not proof. With correlated features, lasso keeps one group member essentially at random, and the selected set can change under resampling. If you need reliable selection, check stability across bootstrap resamples or use elastic net, and confirm candidate features with domain knowledge or held-out evaluation.