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||_Fro^2
Where:
||W||_21 = \sum_i \sqrt{\sum_j w_{ij}^2}
i.e. the sum of norm of each row.
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. eps=1e-3
means that alpha_min / alpha_max = 1e-3
.
Number 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).
See also
MultiTaskElasticNet
Multi-task ElasticNet model trained with L1/L2 mixed-norm as regularizer.
MultiTaskElasticNetCV
Multi-task L1/L2 ElasticNet with built-in cross-validation.
ElasticNet
Linear regression with combined L1 and L2 priors as regularizer.
ElasticNetCV
Elastic Net model with iterative fitting along a regularization path.
Notes
For an example, see examples/linear_model/plot_lasso_lasso_lars_elasticnet_path.py.
Examples
>>> 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=True, random_state=0 ... ) >>> true_coef array([ 0. , 0. , 0. , 97.9, 45.7]) >>> alphas, estimated_coef, _ = enet_path(X, y, n_alphas=3) >>> alphas.shape (3,) >>> estimated_coef array([[ 0., 0.787, 0.568], [ 0., 1.120, 0.620], [-0., -2.129, -1.128], [ 0., 23.046, 88.939], [ 0., 10.637, 41.566]])
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4