skglm.ElasticNet#
- class skglm.ElasticNet(alpha=1.0, l1_ratio=0.5, max_iter=50, max_epochs=50000, p0=10, verbose=0, tol=0.0001, positive=False, fit_intercept=True, warm_start=False, ws_strategy='subdiff')[source]#
Elastic net estimator.
The optimization objective for Elastic net is:
`1 / (2 xx n_"samples") ||y - Xw||_2 ^ 2 + tt"l1_ratio" xx alpha ||w||_1 + (1 - tt"l1_ratio") xx alpha/2 ||w||_2 ^ 2`- Parameters:
- alphafloat, optional
Penalty strength.
- l1_ratiofloat, default=0.5
The ElasticNet mixing parameter, with
0 <= l1_ratio <= 1
. Forl1_ratio = 0
the penalty is an L2 penalty.For l1_ratio = 1
it is an L1 penalty. For0 < l1_ratio < 1
, the penalty is a combination of L1 and L2.- max_iterint, optional
The maximum number of iterations (subproblem definitions).
- max_epochsint
Maximum number of CD epochs on each subproblem.
- p0int
First working set size.
- verbosebool or int
Amount of verbosity.
- tolfloat, optional
Stopping criterion for the optimization.
- positivebool, optional
When set to
True
, forces the coefficient vector to be positive.- fit_interceptbool, optional (default=True)
Whether or not to fit an intercept.
- warm_startbool, optional (default=False)
When set to
True
, reuse the solution of the previous call to fit as initialization, otherwise, just erase the previous solution.- ws_strategystr
The score used to build the working set. Can be
fixpoint
orsubdiff
.
See also
Lasso
Lasso regularization.
- Attributes:
- coef_array, shape (n_features,)
parameter vector (`w` in the cost function formula)
- sparse_coef_scipy.sparse matrix, shape (n_features, 1)
sparse_coef_
is a readonly property derived fromcoef_
- intercept_float
constant term in decision function.
- n_iter_int
Number of subproblems solved to reach the specified tolerance.
- __init__(alpha=1.0, l1_ratio=0.5, max_iter=50, max_epochs=50000, p0=10, verbose=0, tol=0.0001, positive=False, fit_intercept=True, warm_start=False, ws_strategy='subdiff')[source]#
Methods
__init__
([alpha, l1_ratio, max_iter, ...])fit
(X, y)Fit the model according to the given training data.
get_metadata_routing
()Get metadata routing of this object.
get_params
([deep])Get parameters for this estimator.
path
(X, y, alphas[, coef_init, return_n_iter])Compute Elastic Net path.
predict
(X)Predict using the linear model.
score
(X, y[, sample_weight])Return the coefficient of determination of the prediction.
set_params
(**params)Set the parameters of this estimator.
set_score_request
(*[, sample_weight])Request metadata passed to the
score
method.