Documentation
Classes
ElasticNetCV

ElasticNetCV

Elastic Net model with iterative fitting along a regularization path.

See glossary entry for cross-validation estimator.

Read more in the User Guide.

Python Reference (opens in a new tab)

Constructors

constructor()

Signature

new ElasticNetCV(opts?: object): ElasticNetCV;

Parameters

NameTypeDescription
opts?object-
opts.alphas?ArrayLikeList of alphas where to compute the models. If undefined alphas are set automatically.
opts.copy_X?booleanIf true, X will be copied; else, it may be overwritten. Default Value true
opts.cv?numberDetermines the cross-validation splitting strategy. Possible inputs for cv are:
opts.eps?numberLength of the path. eps=1e-3 means that alpha\_min / alpha\_max \= 1e-3. Default Value 0.001
opts.fit_intercept?booleanWhether to calculate the intercept for this model. If set to false, no intercept will be used in calculations (i.e. data is expected to be centered). Default Value true
opts.l1_ratio?numberFloat between 0 and 1 passed to ElasticNet (scaling between l1 and l2 penalties). For l1\_ratio \= 0 the penalty is an L2 penalty. For l1\_ratio \= 1 it is an L1 penalty. For 0 < l1\_ratio < 1, the penalty is a combination of L1 and L2 This parameter can be a list, in which case the different values are tested by cross-validation and the one giving the best prediction score is used. Note that a good choice of list of values for l1_ratio is often to put more values close to 1 (i.e. Lasso) and less close to 0 (i.e. Ridge), as in \[.1, .5, .7, .9, .95, .99, 1\]. Default Value 0.5
opts.max_iter?numberThe maximum number of iterations. Default Value 1000
opts.n_alphas?numberNumber of alphas along the regularization path, used for each l1_ratio. Default Value 100
opts.n_jobs?numberNumber of CPUs to use during the cross validation. undefined means 1 unless in a joblib.parallel\_backend (opens in a new tab) context. \-1 means using all processors. See Glossary for more details.
opts.positive?booleanWhen set to true, forces the coefficients to be positive. Default Value false
opts.precompute?boolean | ArrayLike[] | "auto"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. Default Value 'auto'
opts.random_state?numberThe seed of the pseudo random number generator that selects a random feature to update. Used when selection == ‘random’. Pass an int for reproducible output across multiple function calls. See Glossary.
opts.selection?"random" | "cyclic"If set to ‘random’, a random coefficient is updated every iteration rather than looping over features sequentially by default. This (setting to ‘random’) often leads to significantly faster convergence especially when tol is higher than 1e-4. Default Value 'cyclic'
opts.tol?numberThe tolerance for the optimization: if the updates are smaller than tol, the optimization code checks the dual gap for optimality and continues until it is smaller than tol. Default Value 0.0001
opts.verbose?number | booleanAmount of verbosity. Default Value 0

Returns

ElasticNetCV

Defined in: generated/linear_model/ElasticNetCV.ts:25 (opens in a new tab)

Properties

_isDisposed

boolean = false

Defined in: generated/linear_model/ElasticNetCV.ts:23 (opens in a new tab)

_isInitialized

boolean = false

Defined in: generated/linear_model/ElasticNetCV.ts:22 (opens in a new tab)

_py

PythonBridge

Defined in: generated/linear_model/ElasticNetCV.ts:21 (opens in a new tab)

id

string

Defined in: generated/linear_model/ElasticNetCV.ts:18 (opens in a new tab)

opts

any

Defined in: generated/linear_model/ElasticNetCV.ts:19 (opens in a new tab)

Accessors

alpha_

The amount of penalization chosen by cross validation.

Signature

alpha_(): Promise<number>;

Returns

Promise<number>

Defined in: generated/linear_model/ElasticNetCV.ts:487 (opens in a new tab)

alphas_

The grid of alphas used for fitting, for each l1_ratio.

Signature

alphas_(): Promise<ArrayLike>;

Returns

Promise<ArrayLike>

Defined in: generated/linear_model/ElasticNetCV.ts:608 (opens in a new tab)

coef_

Parameter vector (w in the cost function formula).

Signature

coef_(): Promise<ArrayLike>;

Returns

Promise<ArrayLike>

Defined in: generated/linear_model/ElasticNetCV.ts:535 (opens in a new tab)

dual_gap_

The dual gaps at the end of the optimization for the optimal alpha.

Signature

dual_gap_(): Promise<number>;

Returns

Promise<number>

Defined in: generated/linear_model/ElasticNetCV.ts:631 (opens in a new tab)

feature_names_in_

Names of features seen during fit. Defined only when X has feature names that are all strings.

Signature

feature_names_in_(): Promise<ArrayLike>;

Returns

Promise<ArrayLike>

Defined in: generated/linear_model/ElasticNetCV.ts:704 (opens in a new tab)

intercept_

Independent term in the decision function.

Signature

intercept_(): Promise<number | ArrayLike[]>;

Returns

Promise<number | ArrayLike[]>

Defined in: generated/linear_model/ElasticNetCV.ts:558 (opens in a new tab)

l1_ratio_

The compromise between l1 and l2 penalization chosen by cross validation.

Signature

l1_ratio_(): Promise<number>;

Returns

Promise<number>

Defined in: generated/linear_model/ElasticNetCV.ts:510 (opens in a new tab)

mse_path_

Mean square error for the test set on each fold, varying l1_ratio and alpha.

Signature

mse_path_(): Promise<ArrayLike[][]>;

Returns

Promise<ArrayLike[][]>

Defined in: generated/linear_model/ElasticNetCV.ts:583 (opens in a new tab)

n_features_in_

Number of features seen during fit.

Signature

n_features_in_(): Promise<number>;

Returns

Promise<number>

Defined in: generated/linear_model/ElasticNetCV.ts:679 (opens in a new tab)

n_iter_

Number of iterations run by the coordinate descent solver to reach the specified tolerance for the optimal alpha.

Signature

n_iter_(): Promise<number>;

Returns

Promise<number>

Defined in: generated/linear_model/ElasticNetCV.ts:656 (opens in a new tab)

py

Signature

py(): PythonBridge;

Returns

PythonBridge

Defined in: generated/linear_model/ElasticNetCV.ts:127 (opens in a new tab)

Signature

py(pythonBridge: PythonBridge): void;

Parameters

NameType
pythonBridgePythonBridge

Returns

void

Defined in: generated/linear_model/ElasticNetCV.ts:131 (opens in a new tab)

Methods

dispose()

Disposes of the underlying Python resources.

Once dispose() is called, the instance is no longer usable.

Signature

dispose(): Promise<void>;

Returns

Promise<void>

Defined in: generated/linear_model/ElasticNetCV.ts:194 (opens in a new tab)

fit()

Fit linear model with coordinate descent.

Fit is on grid of alphas and best alpha estimated by cross-validation.

Signature

fit(opts: object): Promise<any>;

Parameters

NameTypeDescription
optsobject-
opts.X?ArrayLikeTraining data. Pass directly as Fortran-contiguous data to avoid unnecessary memory duplication. If y is mono-output, X can be sparse.
opts.sample_weight?number | ArrayLikeSample weights used for fitting and evaluation of the weighted mean squared error of each cv-fold. Note that the cross validated MSE that is finally used to find the best model is the unweighted mean over the (weighted) MSEs of each test fold.
opts.y?ArrayLikeTarget values.

Returns

Promise<any>

Defined in: generated/linear_model/ElasticNetCV.ts:213 (opens in a new tab)

init()

Initializes the underlying Python resources.

This instance is not usable until the Promise returned by init() resolves.

Signature

init(py: PythonBridge): Promise<void>;

Parameters

NameType
pyPythonBridge

Returns

Promise<void>

Defined in: generated/linear_model/ElasticNetCV.ts:140 (opens in a new tab)

path()

Compute elastic net path with coordinate descent.

The elastic net optimization function varies for mono and multi-outputs.

For mono-output tasks it is:

Signature

path(opts: object): Promise<ArrayLike>;

Parameters

NameTypeDescription
optsobject-
opts.X?ArrayLikeTraining data. Pass directly as Fortran-contiguous data to avoid unnecessary memory duplication. If y is mono-output then X can be sparse.
opts.Xy?ArrayLikeXy = np.dot(X.T, y) that can be precomputed. It is useful only when the Gram matrix is precomputed.
opts.alphas?ArrayLikeList of alphas where to compute the models. If undefined alphas are set automatically.
opts.check_input?booleanIf 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. Default Value true
opts.coef_init?ArrayLikeThe initial values of the coefficients.
opts.copy_X?booleanIf true, X will be copied; else, it may be overwritten. Default Value true
opts.eps?numberLength of the path. eps=1e-3 means that alpha\_min / alpha\_max \= 1e-3. Default Value 0.001
opts.l1_ratio?numberNumber between 0 and 1 passed to elastic net (scaling between l1 and l2 penalties). l1\_ratio=1 corresponds to the Lasso. Default Value 0.5
opts.n_alphas?numberNumber of alphas along the regularization path. Default Value 100
opts.params?anyKeyword arguments passed to the coordinate descent solver.
opts.positive?booleanIf set to true, forces coefficients to be positive. (Only allowed when y.ndim \== 1). Default Value false
opts.precompute?boolean | ArrayLike[] | "auto"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. Default Value 'auto'
opts.return_n_iter?booleanWhether to return the number of iterations or not. Default Value false
opts.verbose?number | booleanAmount of verbosity. Default Value false
opts.y?anyTarget values.

Returns

Promise<ArrayLike>

Defined in: generated/linear_model/ElasticNetCV.ts:264 (opens in a new tab)

predict()

Predict using the linear model.

Signature

predict(opts: object): Promise<any>;

Parameters

NameTypeDescription
optsobject-
opts.X?anySamples.

Returns

Promise<any>

Defined in: generated/linear_model/ElasticNetCV.ts:405 (opens in a new tab)

score()

Return the coefficient of determination of the prediction.

The coefficient of determination \(R^2\) is defined as \((1 - \frac{u}{v})\), where \(u\) is the residual sum of squares ((y\_true \- y\_pred)\*\* 2).sum() and \(v\) is the total sum of squares ((y\_true \- y\_true.mean()) \*\* 2).sum(). The best possible score is 1.0 and it can be negative (because the model can be arbitrarily worse). A constant model that always predicts the expected value of y, disregarding the input features, would get a \(R^2\) score of 0.0.

Signature

score(opts: object): Promise<number>;

Parameters

NameTypeDescription
optsobject-
opts.X?ArrayLike[]Test samples. For some estimators this may be a precomputed kernel matrix or a list of generic objects instead with shape (n\_samples, n\_samples\_fitted), where n\_samples\_fitted is the number of samples used in the fitting for the estimator.
opts.sample_weight?ArrayLikeSample weights.
opts.y?ArrayLikeTrue values for X.

Returns

Promise<number>

Defined in: generated/linear_model/ElasticNetCV.ts:440 (opens in a new tab)