DocumentationClassesLinearRegression

Class: LinearRegression

Ordinary least squares Linear Regression.

LinearRegression fits a linear model with coefficients w = (w1, …, wp) to minimize the residual sum of squares between the observed targets in the dataset, and the targets predicted by the linear approximation.

Python Reference

Constructors

new LinearRegression()

new LinearRegression(opts?): LinearRegression

Parameters

ParameterTypeDescription
opts?object-
opts.copy_X?booleanIf true, X will be copied; else, it may be overwritten.
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).
opts.n_jobs?numberThe number of jobs to use for the computation. This will only provide speedup in case of sufficiently large problems, that is if firstly n_targets > 1 and secondly X is sparse or if positive is set to true. undefined means 1 unless in a joblib.parallel_backend context. \-1 means using all processors. See Glossary for more details.
opts.positive?booleanWhen set to true, forces the coefficients to be positive. This option is only supported for dense arrays.

Returns LinearRegression

Defined in generated/linear_model/LinearRegression.ts:23

Properties

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

Accessors

coef_

Get Signature

get coef_(): Promise<any[]>

Estimated coefficients for the linear regression problem. If multiple targets are passed during the fit (y 2D), this is a 2D array of shape (n_targets, n_features), while if only one target is passed, this is a 1D array of length n_features.

Returns Promise<any[]>

Defined in generated/linear_model/LinearRegression.ts:367


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/LinearRegression.ts:502


intercept_

Get Signature

get intercept_(): Promise<number | any[]>

Independent term in the linear model. Set to 0.0 if fit_intercept \= False.

Returns Promise<number | any[]>

Defined in generated/linear_model/LinearRegression.ts:448


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/LinearRegression.ts:475


py

Get Signature

get py(): PythonBridge

Returns PythonBridge

Set Signature

set py(pythonBridge): void

Parameters

ParameterType
pythonBridgePythonBridge

Returns void

Defined in generated/linear_model/LinearRegression.ts:54


rank_

Get Signature

get rank_(): Promise<number>

Rank of matrix X. Only available when X is dense.

Returns Promise<number>

Defined in generated/linear_model/LinearRegression.ts:394


singular_

Get Signature

get singular_(): Promise<any[]>

Singular values of X. Only available when X is dense.

Returns Promise<any[]>

Defined in generated/linear_model/LinearRegression.ts:421

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/LinearRegression.ts:108


fit()

fit(opts): Promise<any>

Fit linear model.

Parameters

ParameterTypeDescription
optsobject-
opts.sample_weight?ArrayLikeIndividual weights for each sample.
opts.X?ArrayLikeTraining data.
opts.y?ArrayLikeTarget values. Will be cast to X’s dtype if necessary.

Returns Promise<any>

Defined in generated/linear_model/LinearRegression.ts:125


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/LinearRegression.ts:171


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/LinearRegression.ts:67


predict()

predict(opts): Promise<any>

Predict using the linear model.

Parameters

ParameterTypeDescription
optsobject-
opts.X?anySamples.

Returns Promise<any>

Defined in generated/linear_model/LinearRegression.ts:207


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/LinearRegression.ts:243


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/LinearRegression.ts:291


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/LinearRegression.ts:331