Class: ElasticNetCV
Elastic Net model with iterative fitting along a regularization path.
See glossary entry for cross-validation estimator.
Read more in the User Guide.
Constructors
new ElasticNetCV()
new ElasticNetCV(
opts
?):ElasticNetCV
Parameters
Parameter | Type | Description |
---|---|---|
opts ? | object | - |
opts.alphas ? | ArrayLike | List of alphas where to compute the models. If undefined alphas are set automatically. |
opts.copy_X ? | boolean | If true , X will be copied; else, it may be overwritten. |
opts.cv ? | number | Determines the cross-validation splitting strategy. Possible inputs for cv are: |
opts.eps ? | number | Length of the path. eps=1e-3 means that alpha_min / alpha_max \= 1e-3 . |
opts.fit_intercept ? | boolean | Whether 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). |
opts.l1_ratio ? | number | Float 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\] . |
opts.max_iter ? | number | The maximum number of iterations. |
opts.n_alphas ? | number | Number of alphas along the regularization path, used for each l1_ratio. |
opts.n_jobs ? | number | Number of CPUs to use during the cross validation. undefined means 1 unless in a joblib.parallel_backend context. \-1 means using all processors. See Glossary for more details. |
opts.positive ? | boolean | When set to true , forces the coefficients to be positive. |
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. |
opts.random_state ? | number | The 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. |
opts.tol ? | number | The 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 . |
opts.verbose ? | number | boolean | Amount of verbosity. |
Returns ElasticNetCV
Defined in generated/linear_model/ElasticNetCV.ts:25
Properties
Property | Type | Default value | Defined in |
---|---|---|---|
_isDisposed | boolean | false | generated/linear_model/ElasticNetCV.ts:23 |
_isInitialized | boolean | false | generated/linear_model/ElasticNetCV.ts:22 |
_py | PythonBridge | undefined | generated/linear_model/ElasticNetCV.ts:21 |
id | string | undefined | generated/linear_model/ElasticNetCV.ts:18 |
opts | any | undefined | generated/linear_model/ElasticNetCV.ts:19 |
Accessors
alpha_
Get Signature
get alpha_():
Promise
<number
>
The amount of penalization chosen by cross validation.
Returns Promise
<number
>
Defined in generated/linear_model/ElasticNetCV.ts:555
alphas_
Get Signature
get alphas_():
Promise
<ArrayLike
>
The grid of alphas used for fitting, for each l1_ratio.
Returns Promise
<ArrayLike
>
Defined in generated/linear_model/ElasticNetCV.ts:676
coef_
Get Signature
get coef_():
Promise
<ArrayLike
>
Parameter vector (w in the cost function formula).
Returns Promise
<ArrayLike
>
Defined in generated/linear_model/ElasticNetCV.ts:603
dual_gap_
Get Signature
get dual_gap_():
Promise
<number
>
The dual gaps at the end of the optimization for the optimal alpha.
Returns Promise
<number
>
Defined in generated/linear_model/ElasticNetCV.ts:699
feature_names_in_
Get Signature
get feature_names_in_():
Promise
<ArrayLike
>
Names of features seen during fit. Defined only when X
has feature names that are all strings.
Returns Promise
<ArrayLike
>
Defined in generated/linear_model/ElasticNetCV.ts:772
intercept_
Get Signature
get intercept_():
Promise
<number
|ArrayLike
[]>
Independent term in the decision function.
Returns Promise
<number
| ArrayLike
[]>
Defined in generated/linear_model/ElasticNetCV.ts:626
l1_ratio_
Get Signature
get l1_ratio_():
Promise
<number
>
The compromise between l1 and l2 penalization chosen by cross validation.
Returns Promise
<number
>
Defined in generated/linear_model/ElasticNetCV.ts:578
mse_path_
Get Signature
get mse_path_():
Promise
<ArrayLike
[][]>
Mean square error for the test set on each fold, varying l1_ratio and alpha.
Returns Promise
<ArrayLike
[][]>
Defined in generated/linear_model/ElasticNetCV.ts:651
n_features_in_
Get Signature
get n_features_in_():
Promise
<number
>
Number of features seen during fit.
Returns Promise
<number
>
Defined in generated/linear_model/ElasticNetCV.ts:747
n_iter_
Get Signature
get n_iter_():
Promise
<number
>
Number of iterations run by the coordinate descent solver to reach the specified tolerance for the optimal alpha.
Returns Promise
<number
>
Defined in generated/linear_model/ElasticNetCV.ts:724
py
Get Signature
get py():
PythonBridge
Returns PythonBridge
Set Signature
set py(
pythonBridge
):void
Parameters
Parameter | Type |
---|---|
pythonBridge | PythonBridge |
Returns void
Defined in generated/linear_model/ElasticNetCV.ts:127
Methods
dispose()
dispose():
Promise
<void
>
Disposes of the underlying Python resources.
Once dispose()
is called, the instance is no longer usable.
Returns Promise
<void
>
Defined in generated/linear_model/ElasticNetCV.ts:179
fit()
fit(
opts
):Promise
<any
>
Fit ElasticNet model with coordinate descent.
Fit is on grid of alphas and best alpha estimated by cross-validation.
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.params ? | any | Parameters to be passed to the CV splitter. |
opts.sample_weight ? | number | ArrayLike | Sample 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.X ? | ArrayLike | Training data. Pass directly as Fortran-contiguous data to avoid unnecessary memory duplication. If y is mono-output, X can be sparse. Note that large sparse matrices and arrays requiring int64 indices are not accepted. |
opts.y ? | ArrayLike | Target values. |
Returns Promise
<any
>
Defined in generated/linear_model/ElasticNetCV.ts:198
get_metadata_routing()
get_metadata_routing(
opts
):Promise
<any
>
Get metadata routing of this object.
Please check User Guide on how the routing mechanism works.
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.routing ? | any | A MetadataRouter encapsulating routing information. |
Returns Promise
<any
>
Defined in generated/linear_model/ElasticNetCV.ts:247
init()
init(
py
):Promise
<void
>
Initializes the underlying Python resources.
This instance is not usable until the Promise
returned by init()
resolves.
Parameters
Parameter | Type |
---|---|
py | PythonBridge |
Returns Promise
<void
>
Defined in generated/linear_model/ElasticNetCV.ts:140
path()
path(
opts
):Promise
<ArrayLike
>
Compute elastic net path with coordinate descent.
The elastic net optimization function varies for mono and multi-outputs.
For mono-output tasks it is:
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.alphas ? | ArrayLike | List of alphas where to compute the models. If undefined alphas are set automatically. |
opts.check_input ? | boolean | 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. |
opts.coef_init ? | ArrayLike | The initial values of the coefficients. |
opts.copy_X ? | boolean | If true , X will be copied; else, it may be overwritten. |
opts.eps ? | number | Length of the path. eps=1e-3 means that alpha_min / alpha_max \= 1e-3 . |
opts.l1_ratio ? | number | Number between 0 and 1 passed to elastic net (scaling between l1 and l2 penalties). l1_ratio=1 corresponds to the Lasso. |
opts.n_alphas ? | number | Number of alphas along the regularization path. |
opts.params ? | any | Keyword arguments passed to the coordinate descent solver. |
opts.positive ? | boolean | If set to true , forces coefficients to be positive. (Only allowed when y.ndim \== 1 ). |
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. |
opts.return_n_iter ? | boolean | Whether to return the number of iterations or not. |
opts.verbose ? | number | boolean | Amount of verbosity. |
opts.X ? | ArrayLike | Training data. Pass directly as Fortran-contiguous data to avoid unnecessary memory duplication. If y is mono-output then X can be sparse. |
opts.Xy ? | ArrayLike | Xy = np.dot(X.T, y) that can be precomputed. It is useful only when the Gram matrix is precomputed. |
opts.y ? | any | Target values. |
Returns Promise
<ArrayLike
>
Defined in generated/linear_model/ElasticNetCV.ts:285
predict()
predict(
opts
):Promise
<any
>
Predict using the linear model.
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.X ? | any | Samples. |
Returns Promise
<any
>
Defined in generated/linear_model/ElasticNetCV.ts:405
score()
score(
opts
):Promise
<number
>
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.
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.sample_weight ? | ArrayLike | Sample weights. |
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.y ? | ArrayLike | True values for X . |
Returns Promise
<number
>
Defined in generated/linear_model/ElasticNetCV.ts:439
set_fit_request()
set_fit_request(
opts
):Promise
<any
>
Request metadata passed to the fit
method.
Note that this method is only relevant if enable_metadata_routing=True
(see sklearn.set_config
). Please see User Guide on how the routing mechanism works.
The options for each parameter are:
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.sample_weight ? | string | boolean | Metadata routing for sample_weight parameter in fit . |
Returns Promise
<any
>
Defined in generated/linear_model/ElasticNetCV.ts:485
set_score_request()
set_score_request(
opts
):Promise
<any
>
Request metadata passed to the score
method.
Note that this method is only relevant if enable_metadata_routing=True
(see sklearn.set_config
). Please see User Guide on how the routing mechanism works.
The options for each parameter are:
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.sample_weight ? | string | boolean | Metadata routing for sample_weight parameter in score . |
Returns Promise
<any
>
Defined in generated/linear_model/ElasticNetCV.ts:521