Elastic Net combines L1 and L2 regularization into a single penalty — getting Lasso's automatic feature selection alongside Ridge's more stable handling of correlated features, instead of having to pick strictly one or the other.
Formula
\(\rho\) (the "L1 ratio," between 0 and 1) controls the mix: \(\rho=1\) recovers pure Lasso, \(\rho=0\) recovers pure Ridge, and values in between blend both penalties' behavior.
Why This Combination Solves a Real Lasso Weakness
Plain Lasso, when facing a group of highly correlated features, tends to arbitrarily select just one and zero out the rest — an unstable, somewhat arbitrary choice. Elastic Net's added L2 component encourages correlated features to be selected (or shrunk) together, rather than picking one winner arbitrarily — combining sparsity with more grouped, stable behavior.
Python Implementation
from sklearn.linear_model import ElasticNet
from sklearn.model_selection import GridSearchCV
param_grid = {
"alpha": [0.01, 0.1, 1, 10],
"l1_ratio": [0.1, 0.5, 0.7, 0.9, 1.0], # 1.0 = pure Lasso, 0.0 = pure Ridge
}
grid_search = GridSearchCV(ElasticNet(), param_grid, cv=5, scoring="neg_mean_squared_error")
grid_search.fit(X_train, y_train)
print("Best params:", grid_search.best_params_)
Practical Use Cases
- High-dimensional data with groups of correlated features, where you still want some feature selection
- Genomics and other domains where features are naturally grouped and correlated, and Lasso's arbitrary single-feature selection is undesirable
The Real Cost — An Extra Hyperparameter
Elastic Net requires tuning two hyperparameters (\(\lambda\) and \(\rho\)) instead of one, meaningfully increasing the tuning search space compared to plain Lasso or Ridge — a real practical tradeoff for its added flexibility.
Common Mistakes
- Defaulting to Elastic Net without first checking whether plain Lasso or Ridge alone would already work fine — the extra tuning complexity is only worth it when correlated-feature grouping is genuinely a concern.
- Fixing \(\rho\) arbitrarily instead of tuning it alongside \(\lambda\) — the right mix genuinely depends on the data's correlation structure.
Interview Relevance
Q: "When would you choose Elastic Net over plain Lasso?" When features are both numerous (suggesting feature selection is useful) and meaningfully correlated in groups (where plain Lasso's tendency to arbitrarily pick one feature per group and zero the rest would be unstable) — Elastic Net's added L2 component encourages more stable, grouped selection behavior.
Practice Question
You have a dataset with 5 highly correlated features representing slightly different measurements of the same underlying quantity. Would you lean toward Lasso or Elastic Net, and why?