sklearn.linear model.ElasticNetCV

From GM-RKB
Jump to navigation Jump to search

A sklearn.linear_model.ElasticNetCV is an ElasticNet Cross-Validation System within sklearn.linear_model class.

  • Context
    • Usage:
1) Import ElasticNetCV model from scikit-learn : from sklearn.linear_model import ElasticNetCV
2) Create design matrix X and response vector Y
3) Create ElasticNetCV object: model=ElasticNetCV(l1_ratio=0.5, eps=0.001, [n_alphas=100, alphas=None, fit_intercept=True, normalize=False])
4) Choose method(s):
Input: Output:
from sklearn.linear_model import ElasticNetCV
from sklearn.datasets import make_regression
X, y = make_regression(n_features=2, random_state=0)
regr = ElasticNetCV(cv=5, random_state=0)
regr.fit(X, y)
print(regr.alpha_)
print(regr.intercept_)
print(regr.predict(0, 0))
ElasticNetCV(alphas=None, copy_X=True, cv=5, eps=0.001,

fit_intercept=True, l1_ratio=0.5, max_iter=1000, n_alphas=100, n_jobs=1, normalize=False, positive=False, precompute='auto', random_state=0, selection='cyclic', tol=0.0001, verbose=0)

0.19947279427
0.398882965428
0.39888297


References

2017A

Elastic Net model with iterative fitting along a regularization path
The best model is selected by cross-validation.
(...)
For an example, see [examples/linear_model/plot_lasso_model_selection.py].
To avoid unnecessary memory duplication the X argument of the fit method should be directly passed as a Fortran-contiguous numpy array.
The parameter l1_ratio corresponds to alpha in the glmnet R package while alpha corresponds to the lambda parameter in glmnet. More specifically, the optimization objective is:
1 / (2 * n_samples) * ||y - Xw||^2_2
+ alpha * l1_ratio * ||w||_1
+ 0.5 * alpha * (1 - l1_ratio) * ||w||^2_2
If you are interested in controlling the L1 and L2 penalty separately, keep in mind that this is equivalent to:
a * L1 + b * L2
for:
alpha = a + b and l1_ratio = a / (a + b).

2017B

  • (Scikit Learn, 2017) ⇒ http://scikit-learn.org/stable/modules/grid_search.html
    • QUOTE: 3.2.4.1. Model specific cross-validation

      Some models can fit data for a range of values of some parameter almost as efficiently as fitting the estimator for a single value of the parameter. This feature can be leveraged to perform a more efficient cross-validation used for model selection of this parameter.

      The most common parameter amenable to this strategy is the parameter encoding the strength of the regularizer. In this case we say that we compute the regularization path of the estimator.

Here is the list of such models:

 :: linear_model.ElasticNetCV([l1_ratio, eps,...]), Elastic Net model with iterative fitting along a regularization path;

linear_model.LarsCV([fit_intercept, ...]), Cross-validated Least Angle Regression model
linear_model.LassoCV([eps, n_alphas, ...]), Lasso linear model with iterative fitting along a regularization path;
linear_model.LassoLarsCV([fit_intercept, ...]), Cross-validated Lasso, using the LARS algorithm
linear_model.LogisticRegressionCV([Cs, ...]), Logistic Regression CV (aka logit, MaxEnt) classifier.
linear_model.MultiTaskElasticNetCV([...]), Multi-task L1/L2 ElasticNet with built-in cross-validation.
linear_model.MultiTaskLassoCV([eps, ...]), Multi-task L1/L2 Lasso with built-in cross-validation.
linear_model.OrthogonalMatchingPursuitCV([...]), Cross-validated Orthogonal Matching Pursuit model (OMP)
linear_model.RidgeCV([alphas, ...]), Ridge regression with built-in cross-validation.
linear_model.RidgeClassifierCV([alphas, ...]), Ridge classifier with built-in cross-validation.