Class: Ridge

Linear least squares with l2 regularization.

Minimizes the objective function:

Python Reference

Constructors

new Ridge()

new Ridge(opts?): Ridge

Parameters

ParameterTypeDescription
opts?object-
opts.alpha?numberConstant that multiplies the L2 term, controlling regularization strength. alpha must be a non-negative float i.e. in \[0, inf). When alpha \= 0, the objective is equivalent to ordinary least squares, solved by the LinearRegression object. For numerical reasons, using alpha \= 0 with the Ridge object is not advised. Instead, you should use the LinearRegression object. If an array is passed, penalties are assumed to be specific to the targets. Hence they must correspond in number.
opts.copy_X?booleanIf true, X will be copied; else, it may be overwritten.
opts.fit_intercept?booleanWhether to fit the intercept for this model. If set to false, no intercept will be used in calculations (i.e. X and y are expected to be centered).
opts.max_iter?numberMaximum number of iterations for conjugate gradient solver. For ‘sparse_cg’ and ‘lsqr’ solvers, the default value is determined by scipy.sparse.linalg. For ‘sag’ solver, the default value is 1000. For ‘lbfgs’ solver, the default value is 15000.
opts.positive?booleanWhen set to true, forces the coefficients to be positive. Only ‘lbfgs’ solver is supported in this case.
opts.random_state?numberUsed when solver == ‘sag’ or ‘saga’ to shuffle the data. See Glossary for details.
opts.solver?"auto" | "svd" | "lsqr" | "lbfgs" | "sag" | "saga" | "cholesky" | "sparse_cg"Solver to use in the computational routines:
opts.tol?numberThe precision of the solution (coef_) is determined by tol which specifies a different convergence criterion for each solver:

Returns Ridge

Defined in generated/linear_model/Ridge.ts:23

Properties

PropertyTypeDefault valueDefined in
_isDisposedbooleanfalsegenerated/linear_model/Ridge.ts:21
_isInitializedbooleanfalsegenerated/linear_model/Ridge.ts:20
_pyPythonBridgeundefinedgenerated/linear_model/Ridge.ts:19
idstringundefinedgenerated/linear_model/Ridge.ts:16
optsanyundefinedgenerated/linear_model/Ridge.ts:17

Accessors

coef_

Get Signature

get coef_(): Promise<ArrayLike>

Weight vector(s).

Returns Promise<ArrayLike>

Defined in generated/linear_model/Ridge.ts:383


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/Ridge.ts:473


intercept_

Get Signature

get intercept_(): Promise<number | ArrayLike>

Independent term in decision function. Set to 0.0 if fit_intercept \= False.

Returns Promise<number | ArrayLike>

Defined in generated/linear_model/Ridge.ts:405


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/Ridge.ts:450


n_iter_

Get Signature

get n_iter_(): Promise<ArrayLike>

Actual number of iterations for each target. Available only for sag and lsqr solvers. Other solvers will return undefined.

Returns Promise<ArrayLike>

Defined in generated/linear_model/Ridge.ts:428


py

Get Signature

get py(): PythonBridge

Returns PythonBridge

Set Signature

set py(pythonBridge): void

Parameters

ParameterType
pythonBridgePythonBridge

Returns void

Defined in generated/linear_model/Ridge.ts:92


solver_

Get Signature

get solver_(): Promise<string>

The solver that was used at fit time by the computational routines.

Returns Promise<string>

Defined in generated/linear_model/Ridge.ts:498

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/Ridge.ts:143


fit()

fit(opts): Promise<any>

Fit Ridge regression model.

Parameters

ParameterTypeDescription
optsobject-
opts.sample_weight?number | ArrayLikeIndividual weights for each sample. If given a float, every sample will have the same weight.
opts.X?ArrayLikeTraining data.
opts.y?ArrayLikeTarget values.

Returns Promise<any>

Defined in generated/linear_model/Ridge.ts:160


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

ParameterTypeDescription
optsobject-
opts.routing?anyA MetadataRequest encapsulating routing information.

Returns Promise<any>

Defined in generated/linear_model/Ridge.ts:204


init()

init(py): Promise<void>

Initializes the underlying Python resources.

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

Parameters

ParameterType
pyPythonBridge

Returns Promise<void>

Defined in generated/linear_model/Ridge.ts:105


predict()

predict(opts): Promise<any>

Predict using the linear model.

Parameters

ParameterTypeDescription
optsobject-
opts.X?anySamples.

Returns Promise<any>

Defined in generated/linear_model/Ridge.ts:236


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

ParameterTypeDescription
optsobject-
opts.sample_weight?ArrayLikeSample 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?ArrayLikeTrue values for X.

Returns Promise<number>

Defined in generated/linear_model/Ridge.ts:269


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

ParameterTypeDescription
optsobject-
opts.sample_weight?string | booleanMetadata routing for sample_weight parameter in fit.

Returns Promise<any>

Defined in generated/linear_model/Ridge.ts:315


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

ParameterTypeDescription
optsobject-
opts.sample_weight?string | booleanMetadata routing for sample_weight parameter in score.

Returns Promise<any>

Defined in generated/linear_model/Ridge.ts:351