Documentation
Classes
LinearRegression

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 (opens in a new tab)

Constructors

constructor()

Signature

new LinearRegression(opts?: object): LinearRegression;

Parameters

NameTypeDescription
opts?object-
opts.copy_X?booleanIf true, X will be copied; else, it may be overwritten. Default Value true
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.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 (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. This option is only supported for dense arrays. Default Value false

Returns

LinearRegression

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

Properties

_isDisposed

boolean = false

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

_isInitialized

boolean = false

Defined in: generated/linear_model/LinearRegression.ts:20 (opens in a new tab)

_py

PythonBridge

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

id

string

Defined in: generated/linear_model/LinearRegression.ts:16 (opens in a new tab)

opts

any

Defined in: generated/linear_model/LinearRegression.ts:17 (opens in a new tab)

Accessors

coef_

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.

Signature

coef_(): Promise<any[]>;

Returns

Promise<any[]>

Defined in: generated/linear_model/LinearRegression.ts:263 (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/LinearRegression.ts:398 (opens in a new tab)

intercept_

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

Signature

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

Returns

Promise<number | any[]>

Defined in: generated/linear_model/LinearRegression.ts:344 (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/LinearRegression.ts:371 (opens in a new tab)

py

Signature

py(): PythonBridge;

Returns

PythonBridge

Defined in: generated/linear_model/LinearRegression.ts:54 (opens in a new tab)

Signature

py(pythonBridge: PythonBridge): void;

Parameters

NameType
pythonBridgePythonBridge

Returns

void

Defined in: generated/linear_model/LinearRegression.ts:58 (opens in a new tab)

rank_

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

Signature

rank_(): Promise<number>;

Returns

Promise<number>

Defined in: generated/linear_model/LinearRegression.ts:290 (opens in a new tab)

singular_

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

Signature

singular_(): Promise<any[]>;

Returns

Promise<any[]>

Defined in: generated/linear_model/LinearRegression.ts:317 (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/LinearRegression.ts:111 (opens in a new tab)

fit()

Fit linear model.

Signature

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

Parameters

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

Returns

Promise<any>

Defined in: generated/linear_model/LinearRegression.ts:128 (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/LinearRegression.ts:67 (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/LinearRegression.ts:177 (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/LinearRegression.ts:214 (opens in a new tab)