Home
API
Examples
Github
Home
API
Examples
Github
  • API

    • cluster

      • KMeans
    • datasets

      • Boston
      • HeartDisease
      • Iris
    • decomposition

      • PCA
    • ensemble

      • BaggingClassifier
      • RandomForestClassifier
    • feature_extraction

      • CountVectorizer
    • linear_model

      • Lasso
      • LinearRegression
      • LogisticRegression
      • Ridge
      • SGDClassifier
      • SGDRegressor
    • metrics

      • accuracyScore
      • confusion_matrix
      • mean_absolute_error
      • mean_squared_error
      • mean_squared_log_error
      • zeroOneLoss
    • model_selection

      • KFold
      • train_test_split
    • naive_bayes

      • GaussianNB
      • MultinomialNB
    • neighbors

      • KNeighborsClassifier
    • preprocessing

      • Binarizer
      • Imputer
      • LabelEncoder
      • MinMaxScaler
      • OneHotEncoder
      • PolynomialFeatures
      • add_dummy_feature
      • normalize
    • svm

      • BaseSVM
      • NuSVC
      • NuSVR
      • OneClassSVM
      • SVC
      • SVR
    • tree

      • DecisionTreeClassifier

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

  • constructor

Methods

  • fit

  • fromJSON

  • predict

  • toJSON

Constructors


constructor

⊕ LinearRegression()

Defined in

Parameters:

ParamTypeDefaultDescription

Returns: LinearRegression

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[]null

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
Prev
Lasso
Next
LogisticRegression