Elastic Net, In Full Depth
Ridge handles correlated features gracefully but never drops any. Lasso drops features automatically but picks unstably among correlated ones. Elastic Net combines both penalties to get most of the benefit of each.
What Is Elastic Net?
Same hypothesis as Linear Regression, with both the L2 (Ridge) and L1 (Lasso) penalties added together:
Two hyperparameters now: controls overall regularization strength (same role as in Ridge/Lasso), and controls the mix between the two penalty types. recovers pure Lasso; recovers pure Ridge; anything in between blends them.
Why Mix the Two Penalties?
The correlated-features problem, concretely: suppose two features are near-duplicates of each other (highly correlated). Lasso's L1 penalty, left alone, tends to arbitrarily pick one and zero out the other — small changes in the data (a different train/test split, a different random seed) can flip which one survives, making the model's selected feature set unstable and hard to trust.
The L2 term fixes this specifically: Ridge's penalty doesn't have Lasso's "pick one, zero the rest" behavior — it spreads weight across correlated features roughly evenly. Adding even a little L2 penalty (small but nonzero ) alongside the L1 term stabilizes which features get selected, while the L1 term still does the actual work of zeroing out genuinely irrelevant features.
Gradient
Simply the sum of the Ridge and Lasso gradient terms, weighted by :
In practice, Elastic Net is solved with the same coordinate-descent + soft-thresholding approach as Lasso (see Lasso — Coordinate Descent), just with a rescaled threshold that accounts for the added L2 term. Try it on the exact same synthetic correlated dataset as the Ridge and Lasso studios — drag α between the two extremes and watch the regularization path itself change shape, not just the numbers:
Choosing λ and α
Both are hyperparameters selected via cross-validation (see ML Workflow Fundamentals) — typically a 2D grid search over candidate pairs, since the best mix depends entirely on how correlated the actual features are and how many are truly irrelevant.
Ridge vs. Lasso vs. Elastic Net
| Ridge (L2) | Lasso (L1) | Elastic Net (L1 + L2) | |
|---|---|---|---|
| Drives weights to exactly 0? | No | Yes | Yes |
| Handles correlated features? | Yes, spreads weight | Poorly, picks one arbitrarily | Yes, more stable than pure Lasso |
| Produces a sparse model? | No | Yes | Yes |
| Hyperparameters to tune | 1 () | 1 () | 2 (, ) |
| Good default when unsure? | If you don't need feature selection | If features are mostly independent | Generally the safest default of the three |
Minimal Implementation
The linear model family is complete: Linear Regression → Ridge → Lasso → Elastic Net, each one relaxing an assumption of the last. Next: Logistic Regression — the same linear machinery, adapted for classification instead of regression.