This page

9.2.23.2. sklearn.linear_model.sparse.ElasticNet

class sklearn.linear_model.sparse.ElasticNet(alpha=1.0, rho=0.5, fit_intercept=False, normalize=False, max_iter=1000, tol=0.0001)

Linear Model trained with L1 and L2 prior as regularizer

This implementation works on scipy.sparse X and dense coef_.

rho=1 is the lasso penalty. Currently, rho <= 0.01 is not reliable, unless you supply your own sequence of alpha.

Parameters :

alpha : float

Constant that multiplies the L1 term. Defaults to 1.0

rho : float

The ElasticNet mixing parameter, with 0 < rho <= 1.

coef_ : ndarray of shape n_features

The initial coeffients to warm-start the optimization

fit_intercept: bool :

Whether the intercept should be estimated or not. If False, the data is assumed to be already centered.

TODO: fit_intercept=True is not yet implemented

Notes

The parameter rho corresponds to alpha in the glmnet R package while alpha corresponds to the lambda parameter in glmnet.

Methods

fit
predict
score
set_params
__init__(alpha=1.0, rho=0.5, fit_intercept=False, normalize=False, max_iter=1000, tol=0.0001)
fit(X, y)

Fit current model with coordinate descent

X is expected to be a sparse matrix. For maximum efficiency, use a sparse matrix in CSC format (scipy.sparse.csc_matrix)

predict(X)

Predict using the linear model

Parameters :X : scipy.sparse matrix of shape [n_samples, n_features]
Returns :array, shape = [n_samples] with the predicted real values :
score(X, y)

Returns the coefficient of determination of the prediction

Parameters :

X : array-like, shape = [n_samples, n_features]

Training set.

y : array-like, shape = [n_samples]

Returns :

z : float

set_params(**params)

Set the parameters of the estimator.

The method works on simple estimators as well as on nested objects (such as pipelines). The former have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.

Returns :self :