Elastic Net Regression

Statistics
Introduced by
Hui Zou and Trevor Hastie
Year
2005
Type
Penalized linear regression
Family
Regression / GLM

What does it do?

Elastic net regression fits a linear model by minimising squared error plus a penalty that mixes the L1 (lasso) and L2 (ridge) norms of the coefficients.

The mixing parameter alpha sets the balance between the two penalties, and lambda sets the overall strength of shrinkage. Compared with either penalty alone, it can set some coefficients exactly to zero while keeping groups of strongly correlated predictors together.

The intuition behind the method

Lasso and ridge can be seen as two ends of one spectrum. Lasso sets weak coefficients exactly to zero, but when several predictors are strongly correlated it tends to keep one of them and drop the others, which makes the choice unstable. Ridge shrinks all coefficients smoothly but never sets any of them to zero. Elastic net lies between the two: alpha controls how much of the penalty is lasso-type, and lambda controls how strongly the coefficients are shrunk overall. The original authors reported that strongly correlated predictors tend to enter or leave the model together, which is why the method is often considered when predictors come in related clusters.

History

Hui Zou and Trevor Hastie introduced the elastic net in a 2005 paper in the Journal of the Royal Statistical Society, Series B. They motivated it by the weaknesses of the lasso when there are many more predictors than observations and when predictors are strongly correlated; the paper reports that the lasso is not a satisfactory selection method in the p much larger than n case. The paper combined the L1 and L2 penalties and proposed the LARS-EN algorithm for computing elastic net regularization paths. Coordinate-descent implementations such as glmnet later made fitting the method routine in many software packages.

When to use it

Choose elastic net for a continuous outcome when you have many candidate predictors, especially when there are more predictors than observations (p > n), when predictors are strongly correlated in groups, and when you expect only a subset of them to matter. It is preferred to the lasso when correlated predictors should be kept or dropped together rather than one being picked arbitrarily. Do not use it when you need unbiased coefficient estimates for causal interpretation, because shrinkage pulls coefficients toward zero. It is also a poor choice when inference on specific predictors is the main goal, since standard inference does not carry over. When n is large relative to p and the predictors are weakly correlated, ordinary least squares is usually simpler and sufficient. A practical check is to compare the cross-validated or held-out prediction error of elastic net with that of OLS; if the penalty does not improve prediction, OLS is the simpler choice.

Limitations and considerations

  • Shrinkage biases all coefficient estimates toward zero, so even a correctly specified linear model yields biased estimates.
  • Two tuning parameters, lambda and alpha, must be chosen, which increases the cross-validation cost compared with the lasso or ridge alone.
  • Standard errors and p-values from the penalized fit are not valid OLS quantities; inference after selection needs additional procedures.
  • When predictors are uncorrelated and n is large relative to p, the penalty adds bias without a corresponding benefit, and ordinary least squares is simpler.

Source conditions do not replace independent scientific review or validation by an analysis engine.

Strengths

  • Can be fitted when there are more predictors than observations (p > n), a setting in which ordinary least squares does not give a unique estimate.
  • Sets some coefficients exactly to zero for variable selection, while the L2 term encourages strongly correlated predictors to enter or leave the model together (the grouping effect described by Zou and Hastie).
  • Compared with the lasso, it is more stable when predictors are highly correlated, because the L2 term spreads weight across a correlated group instead of selecting one member of it.
  • The alpha parameter lets the data determine how much of the penalty is lasso-type, so one model covers both ridge-like and lasso-like behaviour.
  • The objective is convex, so any local minimum is also the global minimum, and coordinate descent keeps the computation practical on large problems.

Applications

  • Genomics and bioinformatics: selecting a small set of genes from tens of thousands of correlated expression features.
  • High-dimensional social science surveys: identifying key predictors from a large battery of correlated questionnaire items.
  • Financial modelling: building sparse predictive models from many correlated macroeconomic and market indicators.
  • Text analysis and NLP: penalized regression on high-dimensional, sparse term-frequency matrices.
  • Clinical risk prediction: variable selection among correlated lab values and patient characteristics for a prognostic score.
  • Environmental science: sparse modelling of pollution concentrations from many intercorrelated meteorological and emission predictors.

How it works

How it works

1

The estimate minimises the ordinary least-squares loss, scaled by 1/(2n), plus lambda times a blend of two penalties: alpha times the L1 norm of the coefficients and (1 - alpha)/2 times the squared L2 norm. The L1 term can drive coefficients exactly to zero, while the squared L2 term shrinks large coefficients smoothly. Both lambda and alpha must be chosen before the fit, either by the user or by cross-validation. This is a common parameterisation with one overall strength (lambda) and one mixing weight (alpha). Other sources write the two penalty weights separately, so check the convention before comparing lambda values across sources or software.

Formula
\min_{\beta} \left\{ \frac{1}{2n}\|y - X\beta\|_2^2 + \lambda\left[\alpha\|\beta\|_1 + \frac{1-\alpha}{2}\|\beta\|_2^2\right] \right\}
2

The mixing parameter alpha lies between 0 and 1. At alpha = 1 the penalty is the lasso penalty, and at alpha = 0 it is the ridge penalty. Intermediate values combine the variable selection of the L1 term with the grouping behaviour contributed by the L2 term.

Formula
\alpha \in [0,1]: \alpha=1 \Rightarrow \text{LASSO},\; \alpha=0 \Rightarrow \text{Ridge}
3

Both hyperparameters, lambda (overall penalty strength) and alpha (lasso-ridge mix), are selected by k-fold cross-validation. A two-dimensional grid search over (lambda, alpha) pairs identifies the combination with the lowest cross-validated prediction error.

4

For fixed lambda and alpha the objective is convex, because the squared-error loss and both penalty terms are convex, so any local minimum is also a global minimum. It is commonly computed by coordinate descent, as in the glmnet implementation. The solution contains entries that are exactly zero (excluded predictors) and entries that are shrunk toward zero but retained.

5

Classical OLS standard errors, t-statistics and confidence intervals do not apply directly, because shrinkage and the data-driven selection of predictors change the sampling behaviour of the estimates. Uncertainty is usually assessed with bootstrap resampling, post-selection procedures or debiasing methods, each of which has its own assumptions and limitations.

Common pitfalls

  • Reading the penalized coefficients as unbiased causal effect sizes. Because they are shrunk, their magnitudes are systematically understated relative to the unpenalized model.
  • Fitting without standardising the predictors. The penalty acts on raw coefficient sizes, so a predictor measured on a small scale needs a large coefficient to matter and is penalised more heavily than one measured on a large scale.
  • Setting alpha to 1 by default when predictors are correlated, which can make the selected set unstable across resamples.
  • Reporting p-values or intervals from the penalized fit as if they were ordinary OLS output. Use bootstrap or post-selection methods and state which one was used.
  • Reporting the cross-validated error from the tuning folds as the final performance estimate. Those folds chose lambda and alpha, so the estimate is optimistic; hold out a test set that is not used for tuning.
  • Treating a multi-level categorical predictor as one unit. Its dummy coefficients are penalised individually, so some levels may be retained while others are dropped. If the whole factor should enter or leave together, use a group penalty such as the group lasso.

Frequently asked questions

How is elastic net different from lasso and ridge?

Lasso uses only the L1 penalty, which sets some coefficients to zero but tends to select one predictor arbitrarily from a group of correlated predictors. Ridge uses only the L2 penalty, which shrinks all coefficients but never sets them to zero. Elastic net blends both, and the alpha parameter controls the mix. When 0 < alpha < 1, you get simultaneous variable selection and grouping of correlated predictors, which is the main advantage over either penalty alone.

How do I choose alpha and lambda?

Use cross-validation. In practice, run a grid search over a sequence of alpha values (for example 0, 0.25, 0.5, 0.75, 1.0) and, for each alpha, over a log-spaced sequence of lambda values. The endpoints are valid settings: alpha = 0 is pure ridge and alpha = 1 is pure lasso. Select the (alpha, lambda) pair that minimises the cross-validated prediction error. The glmnet package in R and scikit-learn in Python both implement this kind of search.

Do I need to standardize my predictors?

Yes, in general. The L1 and L2 penalties act on raw coefficient magnitudes, so predictors on different scales are penalised unevenly unless they are standardised. Standardise them before fitting, or confirm that your software does so, since implementations differ. Categorical predictors should be converted to numeric (for example dummy) variables before standardisation and penalisation, because the penalty applies to individual coefficients. Back-transform the coefficients if you need them on the original scales.

Can I use elastic net for classification?

The formulation given above uses squared-error loss for a continuous outcome. Replacing that loss with a logistic loss gives elastic-net-penalised logistic regression for binary or multinomial outcomes. It keeps the same penalty structure and the same alpha and lambda tuning approach, but it is a different model, so check your software's documentation for the exact formulation.

Are the coefficient estimates from elastic net unbiased?

No. Regularization intentionally introduces bias to reduce variance and prevent overfitting, so the coefficients are not unbiased by design. If unbiased estimates are essential, for example for causal claims, a penalised fit on its own is not suitable. Standard OLS standard errors and p-values computed on the predictors chosen by the penalty are not valid, because the selection was data-driven. For inference on the selected coefficients, use methods with stated assumptions, such as debiased lasso or selective inference, and check those assumptions for your data.

Related methods

Sources

  1. Zou, H., & Hastie, T. (2005). Regularization and variable selection via the elastic net. Journal of the Royal Statistical Society: Series B (Statistical Methodology), 67(2), 301-320.

    Open DOI reference
  2. Hastie, T., Tibshirani, R., & Friedman, J. (2009). The Elements of Statistical Learning: Data Mining, Inference, and Prediction (2nd ed.). Springer.

    ISBN: 978-0387848570