Elastic Net
Elastic Net — Blend L1 and L2 penalties to get the best of both.
Elastic net mixes ridge and lasso in one penalty. You get lasso’s feature selection plus ridge’s stability with correlated features — controlled by a single mixing dial.
Coefficients at λ = 0.00100, ρ = 0.00 (click one to trace it)
⇄ marks the two strongly correlated features.
- x1
- x2
- x3
- x4
- x5
- x6
Elastic-net controls
The idea in plain words
Elastic net simply adds both penalties at once: a slice of lasso’s L1 for sparsity and a slice of ridge’s L2 for stability. One mixing dial ρ slides between them, and you can watch the constraint region morph from a circle to a diamond as it moves.
The payoff shows up with correlated features. Pure lasso arbitrarily keeps one and drops the rest; the L2 part encourages correlated features to share the weight, so selection stays stable — the best of both penalties from a single knob.
Now, the math
Elastic net is a convex blend of the L1 and L2 penalties:
- the L1 ratio — 1 is pure lasso, 0 is pure ridge, between is a blend.
- the overall strength of the combined penalty.
- the share given to the stabilizing L2 term.
▸ Show the derivation
The constraint region ρ‖w‖₁ + (1−ρ)‖w‖² = c interpolates between the diamond (ρ = 1) and the circle (ρ = 0): its corners stay sharp enough to zero out irrelevant features while its sides round out enough to spread weight across correlated ones. Coordinate descent solves it with the same soft-threshold as lasso, divided by an extra 1 + λ(1−ρ) ridge shrinkage factor.
Trace it by hand
Two perfectly correlated features — identical columns x1 and x2, both equal to (-1, -1, 1, 1) — with targets y equal to 3 x1. The data cannot tell the twins apart, so only the penalty decides how weight is shared. All solutions computed with the repo's coordinate-descent and ridge solvers at lambda equal to 1.
Step 1 — the data alone cannot decide
Plain least squares has no unique answer here; the repo's coordinate descent at lambda 0 happens to land on the split (3, 0).
Step 2 — pure lasso picks one twin, rho equal to 1
Whichever coordinate updates first absorbs the signal; its twin sees nothing left above the threshold. The choice is arbitrary — reorder the features and it flips.
Step 3 — elastic net shares, rho equal to one half
Check the fixed point by hand: each weight sees z of 3 minus 1 equals 2, then 2 minus 0.5 over 1.5 equals exactly 1.
Step 4 — the L2 slice is what forces the tie
Both candidates have the same L1 total of 2, but squaring punishes concentration: 4 plus 0 beats 1 plus 1 on the L2 side, so the even split is cheaper.
Step 5 — same predictions, different story
On these four points the two models output identical predictions — the difference is which features get the credit, and only the elastic net's attribution survives reordering. For comparison, ridge at lambda 1 also lands on (1, 1).
What just happened: With identical features at lambda 1, lasso chose (2, 0) arbitrarily while elastic net at rho one half chose (1, 1): same L1 total, but the L2 slice makes the even split cheaper — penalty 2 versus 3 — so correlated features share the weight. That stability is exactly what elastic net was built for.
Now Break It
Try this: Wrong mixing ratio for the data either over-sparsifies or fails to select at all.
Control: Mixing ratio slider
What happens: Mis-tuned mix! The L1/L2 balance is wrong for this data — either too sparse or not selective enough.
Where elastic net is used
Elastic net blends the L1 and L2 penalties so it can select features like lasso while handling correlated predictors gracefully like ridge, which makes it a strong default in high-dimensional problems. Genomics again is a headline use case: when many genes are correlated within pathways, elastic net keeps whole groups of related genes together rather than arbitrarily dropping all but one, giving biologically sensible models. It is widely used in predictive modeling on wide datasets such as marketing response, credit risk with many overlapping indicators, and text or web features where vocabularies are large and redundant. Practitioners often adopt elastic net whenever they would consider lasso but worry about correlated inputs or datasets with more features than samples, gaining sparsity and stability at once.
A common misconception is that elastic net is simply lasso with a safety net and therefore always superior; in reality it has two knobs, the overall penalty strength and the mixing ratio between L1 and L2, and both must be tuned jointly by cross-validation, which costs more effort. Another pitfall is misunderstanding the mixing parameter: setting it fully toward L1 recovers plain lasso and fully toward L2 recovers ridge, so a poorly chosen mix can throw away the very grouping behavior that motivates elastic net. As with lasso and ridge, features must be standardized first. Finally, elastic net does not remove the need for domain judgment; its selected groups still require interpretation rather than blind trust.
Frequently asked questions
What is elastic net?
How does elastic net differ from lasso and ridge?
What is the mixing parameter in elastic net?
When should I choose elastic net?
How do I tune elastic net?
Written & reviewed by the ML Visualization team · Last updated .