elastic_net – Elastic net (L1 + L2 hybrid).#
Back to family axis | Back to L4 | Browse all options
Operational op under axis
family, sub-layerL4_A_model_selection, layerl4. Standalone callable:mf.functions.elastic_net_fit.
Function signature#
mf.functions.elastic_net_fit(
X: np.ndarray | pd.DataFrame,
y: np.ndarray | pd.Series,
*,
alpha: float = 1.0,
l1_ratio: float = 0.5,
max_iter: int = 20000,
) -> ElasticNetFitResult
Parameters#
name |
type |
default |
constraint |
description |
|---|---|---|---|---|
|
`np.ndarray |
pd.DataFrame` |
— |
— |
|
`np.ndarray |
pd.Series` |
— |
— |
|
|
|
>=0 |
Overall regularisation strength. |
|
|
|
in [0.0, 1.0] |
L1/L2 mixing parameter. 0 = pure ridge, 1 = pure lasso. |
|
|
|
>=1 |
Maximum number of coordinate descent iterations. |
Returns#
ElasticNetFitResult — frozen dataclass with fit results.
Attribute |
Type |
Description |
|---|---|---|
|
|
Fitted coefficient vector, shape (n_features,). |
|
|
Fitted intercept scalar. |
|
|
Regularisation strength used. |
|
|
L1/L2 mixing parameter used. |
|
|
Predictions for new data X, shape (n_samples,). |
|
|
Human-readable text table of fit results. |
Behavior#
Combines ridge and lasso penalties via params.l1_ratio (0 = ridge, 1 = lasso). Useful when predictors are correlated and pure lasso struggles with the selection.
When to use
Correlated predictor blocks where lasso alone gives unstable selection.
In recipe context#
Set params.family = "elastic_net" in the relevant layer to activate this op within a recipe:
# Layer L4 recipe fragment
params:
family: elastic_net
References#
macroforecast design Part 2, L4: ‘forecasting model is the layer where every authoring iteration ends – pick family, tune, repeat.’
Zou & Hastie (2005) ‘Regularization and variable selection via the elastic net’, JRSS-B 67(2).