linear_model.LinearRegression
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]
Constructors
Methods
Constructors
constructor
⊕ LinearRegression()
Defined in
Parameters:
Param | Type | Default | Description |
---|
Returns: LinearRegression
Methods
λ fit
fit linear model
Defined in linear_model/linear_regression.ts:56
Parameters:
Param | Type | Default | Description |
---|---|---|---|
X | number[] or number[][] | null | training values |
y | number[] or number[][] | null | target values |
Returns:
void
λ fromJSON
Restore the model from a checkpoint
Defined in linear_model/linear_regression.ts:125
Parameters:
Param | Type | Default | Description |
---|---|---|---|
options.weights | number[] | null |
Returns:
void
λ predict
Predict using the linear model
Defined in linear_model/linear_regression.ts:86
Parameters:
Param | Type | Default | Description |
---|---|---|---|
X | number[] or number[][] | null | Values to predict. |
Returns:
number[]
λ toJSON
Get the model details in JSON format
Defined in linear_model/linear_regression.ts:106
Returns:
Param | Type | Description |
---|---|---|
weights | number[] | Coefficients |