ElasticNet
ElasticNet combines (Lasso) and (Ridge) regularization, inheriting sparsity from Lasso and stability from Ridge. It is particularly useful when features are correlated: Lasso tends to arbitrarily select one feature from a correlated group, while ElasticNet distributes weight across them.
Objective Function
where is the l1_ratio controlling the mix between and penalties:
- : pure Lasso
- : pure Ridge (scaled by )
This formulation matches scikit-learn's ElasticNet.
Coordinate Descent
Like Lasso, ElasticNet is solved via coordinate descent. The update for coefficient is:
where and is the soft-thresholding operator. The term adds to the denominator, preventing the instability that Lasso can exhibit with correlated features.
When to Use
- Correlated features: ElasticNet is preferred over Lasso when features are highly correlated.
- Grouped selection: The component encourages correlated features to be selected together.
- Regularization path: ElasticNet's convex combination provides a smooth transition between Ridge and Lasso behavior.
Constructor
Skigen::ElasticNet<Scalar> model(Scalar alpha = 1, Scalar l1_ratio = 0.5,
bool fit_intercept = true,
int max_iter = 1000, Scalar tol = 1e-4);
| Parameter | Default | Description |
|---|---|---|
alpha | 1 | Overall regularization strength () |
l1_ratio | 0.5 | Mix ratio ( = Lasso, = Ridge) |
fit_intercept | true | Whether to center the data and compute an intercept |
max_iter | 1000 | Maximum coordinate descent iterations |
tol | 1e-4 | Convergence tolerance |
Methods
| Method | Description |
|---|---|
fit(X, y) | Fit the model via coordinate descent |
predict(X) | Predict |
score(X, y) | Return the coefficient of determination |
Fitted Attributes
| Accessor | Type | Description |
|---|---|---|
coef() | RowVectorType | Estimated coefficients |
intercept() | Scalar | Intercept term |
Example
#include <Skigen/LinearModel>
Skigen::ElasticNet model(/*alpha=*/0.5, /*l1_ratio=*/0.7);
model.fit(X, y);
auto predictions = model.predict(X_test);
References
- Zou, H. and Hastie, T. (2005). "Regularization and variable selection via the elastic net." Journal of the Royal Statistical Society: Series B, 67(2), 301–320.
API Reference
For full parameter details and method signatures, see the ElasticNet API Reference.