linear_model.LinearRegression

Ordinary least squares Linear Regression. It supports both univariate and multivariate linear regressions.

Usage

import { LinearRegression } from './linear_regression';
const linearRegression = new LinearRegression();
const X = [1, 2, 4, 3, 5];
const y = [1, 3, 3, 2, 5];
linearRegression.fit(X, y);
lr.predict([1, 2]);
// [ 1.1999999999999995, 1.9999999999999996 ]

const linearRegression2 = new LinearRegression();
const X2 = [[1, 1], [1, 2], [2, 2], [2, 3]];
const y2 = [1, 1, 2, 2];
linearRegression2.fit(X2, y2);
lr.predict([[1, 2]]);
// [1.0000001788139343]

Methods

Methods


λ fit

fit linear model

Defined in linear_model/linear_regression.ts:56

Parameters:

ParamTypeDefaultDescription
Xnumber[] or number[][]nulltraining values
ynumber[] or number[][]nulltarget values

Returns:

void

λ fromJSON

Restore the model from a checkpoint

Defined in linear_model/linear_regression.ts:125

Parameters:

ParamTypeDefaultDescription
options.weightsnumber[]nullModel's weights

Returns:

void

λ predict

Predict using the linear model

Defined in linear_model/linear_regression.ts:86

Parameters:

ParamTypeDefaultDescription
Xnumber[] or number[][]nullValues to predict.

Returns:

number[]

λ toJSON

Get the model details in JSON format

Defined in linear_model/linear_regression.ts:106

Returns:

ParamTypeDescription
weightsnumber[]Coefficients