enet_path
- sklearn.linear_model.enet_path(X, y, *, l1_ratio=0.5, eps=0.001, n_alphas='deprecated', alphas='warn', precompute='auto', Xy=, , , , , , ,
Compute elastic net path with coordinate descent.
The elastic net optimization function varies for mono and multi-outputs.
For mono-output tasks it is:
1 / (2 * n_samples) * ||y - Xw||^2_2
+ alpha * l1_ratio * ||w||_1
+ 0.5 * alpha * (1 - l1_ratio) * ||w||^2_2
For multi-output tasks it is:
1 / (2 * n_samples) * ||Y - XW||_Fro^2
+ alpha * l1_ratio * ||W||_21
+ 0.5 * alpha * (1 - l1_ratio) * ||W
Where:
||W||_21 = \sum_i \sqrt{\sum_j w_{ij}^2}
i.e. the sum of L2-norm of each row (task) (i=feature, j=task)
Read more in the User Guide.
Training data. Pass directly as Fortran-contiguous data to avoid
unnecessary memory duplication. If y is mono-output then X
can be sparse.
Target values.
Number between 0 and 1 passed to elastic net (scaling between
l1 and l2 penalties). l1_ratio=1 corresponds to the Lasso.
Length of the path. means that .
For an example, see examples/linear_model/plot_lasso_lasso_lars_elasticnet_path.py.
The underlying coordinate descent solver uses gap safe screening rules to speedup fitting time, see User Guide on coordinate descent.
>>> from sklearn.linear_model import enet_path
>>> from sklearn.datasets import make_regression
>>> X, y, true_coef = make_regression(
... n_samples=100, n_features=5, n_informative=2, coef
eps=1e-3alpha_min / alpha_max = 1e-3Number of alphas along the regularization path.
List of alphas where to compute the models. If None alphas are set automatically.
Whether to use a precomputed Gram matrix to speed up
calculations. If set to 'auto' let us decide. The Gram
matrix can also be passed as argument.
Xy = np.dot(X.T, y) that can be precomputed. It is useful only when the Gram matrix is precomputed.
If True, X will be copied; else, it may be overwritten.
The initial values of the coefficients.
Amount of verbosity.
Whether to return the number of iterations or not.
If set to True, forces coefficients to be positive.
(Only allowed when y.ndim == 1).
If set to False, the input validation checks are skipped (including the Gram matrix when provided). It is assumed that they are handled by the caller.
Keyword arguments passed to the coordinate descent solver.
The alphas along the path where models are computed.
Coefficients along the path.
The dual gaps at the end of the optimization for each alpha.
The number of iterations taken by the coordinate descent optimizer to
reach the specified tolerance for each alpha.
(Is returned when return_n_iter is set to True).
ElasticNetCVElastic Net model with iterative fitting along a regularization path.