Foundations to Frontier
Tests
D. Classical Machine Learning › D1 Linear Models for Regression

Elastic Net

The elastic net combines the lasso and ridge penalties, λ[α‖β‖₁ + (1 − α)/2‖β‖²]. The L1 part still sets coefficients to zero, while the L2 part makes the problem strongly convex, so correlated features are kept or dropped together (the grouping effect), and more than n features can be selected when p > n. It is solved by the same coordinate descent as the lasso with one extra term, and it equals a lasso on augmented data. This page covers the objective, the coordinate update, the grouping theorem, the choice of α and λ, and how the elastic net compares with its parents. In the exercises you implement the elastic net and check its grouping bound; then you compare lasso, elastic net and near-ridge on groups of correlated relevant features with fewer examples than features, measuring accuracy, how many relevant features are kept, and how stable the selection is.

Level 0: Foundation

★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.

Teams of clues

Suppose three thermometers sit side by side, so they always read almost the same. The lasso tends to pick one and ignore the others, a bit arbitrarily. Ridge keeps all three but never switches any off. The elastic net mixes the two rules. It still switches off useless clues, but clues that travel together are kept, or dropped, together as a team.

Elastic-net coefficient paths
large λ (all zero)small λ
mid-path coefficients of the correlated trio: 1.31, 0.96, 0.69 · at small λ: 1.33, 1.04, 0.79
With α = 1 the lasso lets one member of the trio enter first and keeps the others small or zero for a long stretch of the path. Lower α and the three paths move together (the grouping effect): the elastic net keeps or drops correlated features as a group, which makes its selections more stable.
Why engineers care

Sensor arrays, spectra and gene panels come in groups of strongly correlated channels. Selecting a whole group makes the model more stable and easier to interpret (“the strain-gauge cluster near the root matters”) than an arbitrary single channel that flips from dataset to dataset.

📝 Quick check (Level 0)
0/3 answered
  1. 1. The elastic net mixes…
  2. 2. Correlated useful features under the elastic net are…
  3. 3. In the demo, α = 1 is the…

Level 1: Beginner

★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.

One coordinate update by hand

The coordinate update is “soft-threshold by λα, then divide by 1 + λ(1 − α)” (standardised features).

Take a partial correlation ρ = 2 and λ = 1:

α soft-threshold S(2, λα) divide by 1 + λ(1 − α) new βⱼ
1 (lasso) 1 1 1
0.5 1.5 1.5 1
0 (ridge) 2 2 1

With ρ = −0.2 and α = 0.5, |ρ| < 0.5 gives βⱼ = 0. The L1 part decides whether a feature is in; the L2 part shrinks it and shares weight among correlated features.

The steps in plain English:

  1. Standardise the features.
  2. Pick α (e.g. 0.5) and a path of λ values.
  3. Run coordinate descent with the update above, warm-starting along the path.
  4. Choose α and λ by cross-validation.
📝 Quick check (Level 1)
0/3 answered
  1. 1. With α = 0 the elastic net is…
  2. 2. Which part creates exact zeros?
  3. 3. sklearn's l1_ratio corresponds to…

Level 2: Intermediate

★★★☆☆ Intermediate⏱ 35 minUndergraduate students and practising engineers.

Objective and algorithm

Objective: minimise (1/2n)‖y − Xβ‖² + λ[α‖β‖₁ + (1 − α)/2·‖β‖²], with α ∈ [0, 1].

Coordinate update: βⱼ ← S(ρⱼ, λα)/(‖xⱼ‖²/n + λ(1 − α)), with ρⱼ = xⱼᵀr₍ⱼ₎/n.

λ_max = max|xⱼᵀy|/(nα).

Equivalent lasso. With λ₂ = λ(1 − α), the elastic net is a lasso on augmented data:

  • X* = [X; √(nλ₂)·I];
  • y* = [y; 0].

So any lasso solver works, and the problem has a unique solution.

Original vs. naive scaling. Zou and Hastie’s “naive” elastic net shrinks twice, so they rescaled the solution by (1 + λ₂). Modern implementations (glmnet, scikit-learn) use the form above without rescaling.

from sklearn.linear_model import ElasticNetCV
from sklearn.pipeline import make_pipeline; from sklearn.preprocessing import StandardScaler
model = make_pipeline(StandardScaler(), ElasticNetCV(l1_ratio=[0.1, 0.5, 0.7, 0.9, 0.95, 1.0], cv=5)).fit(X, y)
print(model[-1].l1_ratio_, model[-1].alpha_)          # note: sklearn calls the mixing α "l1_ratio" and λ "alpha"

Hyperparameters: λ and the mixing α (sklearn: alpha = λ, l1_ratio = α). Use it when features come in correlated groups, p > n, or the lasso’s selections are unstable. Use the lasso when the sparsest possible model matters and features are not strongly correlated.

🐍 Exercise 1: elastic net by coordinate descent
Implement elastic-net coordinate descent, its λ_max, a KKT check and Zou and Hastie's grouping bound; show that with near-identical twin features the lasso splits weight very unevenly while the elastic net gives them nearly equal coefficients, and that α = 0 reproduces ridge.
📝 Quick check (Level 2)
0/3 answered
  1. 1. Coordinate update with ρ = 3, λ = 2, α = 0.5, unit-variance feature?
  2. 2. The elastic net equals a lasso on…
  3. 3. λ_max for the elastic net is…

Level 3: Advanced

★★★★☆ Advanced⏱ 30 minGraduate level, with full derivations and proofs.

The grouping theorem and comparison

Grouping effect (Zou and Hastie, 2005). For standardised features i and j with correlation ρ, the elastic-net coefficients satisfy

|β̂ᵢ − β̂ⱼ| ≤ ‖y‖₁√(2(1 − ρ))/(nλ(1 − α)).

As ρ → 1 the coefficients become equal. The lasso has no such bound. Its L1 penalty is flat along directions that split weight between same-sign features, so the data and the algorithm decide arbitrarily.

Strong convexity. For α < 1 the objective is strongly convex, so the solution is unique, and coordinate descent converges linearly.

Selection capacity. The lasso selects at most n features when p > n. The elastic net can select more.

Compared with the alternatives:

Ridge Lasso Elastic net
exact zeros no yes yes
correlated groups spreads weight picks one keeps the group
p > n selection — ≤ n features can exceed n
stability of selection n/a low higher

Related: group lasso (predefined groups enter together), sparse group lasso, adaptive elastic net.

Interview questions.

  • When would you choose the elastic net over the lasso? Correlated predictors, p ≫ n, or unstable lasso selections.
  • What does l1_ratio = 0.5 mean in sklearn? Equal weight on the L1 and L2 parts, in the convention above.
📝 Quick check (Level 3)
0/3 answered
  1. 1. The grouping bound shrinks as…
  2. 2. For α < 1 the elastic-net objective is…
  3. 3. When groups are known in advance, consider…

Level 4: Expert

★★★★★ Expert⏱ 30 minResearchers: original papers and open problems.

Correlated groups, measured

History. Zou and Hastie introduced the elastic net in 2005, motivated by microarray data with thousands of correlated genes and few samples. It became the default in glmnet (2010), and it is the standard regulariser in many genomics and spectroscopy pipelines.

Exercise 1. With twin features (correlation ≈ 0.997) and λ = 0.6:

  • the lasso assigns (1.19, 0.20);
  • the elastic net with α = 0.3 assigns (0.75, 0.74), a gap of 0.004, well inside the theoretical bound of 0.32;
  • α = 0 reproduces closed-form ridge.

Exercise 2: three groups of four relevant features. Setup: within-group correlation 0.9, 48 noise features, n = 40 examples for p = 60 features, σ = 2; λ chosen on a validation set; selection stability over 8 bootstrap refits; means over 8 datasets.

Method Test MSE Relevant kept (of 12) False selected Selection stability (Jaccard)
lasso (α = 1) 6.90 8.8 5.1 0.31
elastic net, α = 0.5 7.22 12.0 15.9 0.50
elastic net, α = 0.2 8.23 12.0 30.4 0.69
near-ridge (α = 0.01) 9.55 12.0 46.6 0.98
  • With fewer examples than features, the lasso keeps only about 9 of the 12 relevant features. It drops members of each correlated group, and which ones changes from resample to resample (stability 0.31).
  • The elastic net keeps every relevant feature and selects more consistently, at a similar prediction error (+5%).
  • The cost is more noise features alongside them. Lowering α trades sparsity for stability all the way to ridge.
  • The right α depends on the goal: the sparsest predictive model (lasso), complete and stable groups (elastic net), or plain prediction (often ridge or a tuned α).
🐍 Exercise 2 (research): lasso versus elastic net on correlated groups
With three groups of four correlated relevant features among 60 and only 40 examples, fit the lasso, elastic net (α = 0.5, 0.2) and near-ridge with validation-tuned λ (FISTA); compare test error, relevant features kept, false selections and bootstrap stability of the selected set.

The elastic net in AI, robotics and aerospace

  • Spectroscopy and hyperspectral imaging: neighbouring wavelengths are highly correlated; the elastic net selects contiguous bands.
  • Sensor arrays: groups of co-located accelerometers or strain gauges.
  • Genomics: the original motivation, with many correlated genes and few samples.
  • Regularised GLMs: glmnet’s elastic-net logistic and Poisson regression (D2, D1.15).

References

  1. H. Zou, T. Hastie (2005). “Regularization and variable selection via the elastic net.” JRSS B 67(2).
  2. J. Friedman, T. Hastie, R. Tibshirani (2010). “Regularization paths for generalized linear models via coordinate descent.” Journal of Statistical Software 33(1).
  3. M. Yuan, Y. Lin (2006). “Model selection and estimation in regression with grouped variables.” JRSS B 68(1).
  4. N. Meinshausen, P. Bühlmann (2010). “Stability selection.” JRSS B 72(4).
  5. T. Hastie, R. Tibshirani, M. Wainwright (2015). Statistical Learning with Sparsity. CRC Press.