linear_model.LogisticRegression

Logistic Regression (aka logit, MaxEnt) classifier. Logistic regression is named for the function used at the core of the method, the logistic function. The logistic function, also called the sigmoid function was developed by statisticians to describe properties of population growth in ecology, rising quickly and maxing out at the carrying capacity of the environment. It’s an S-shaped curve that can take any real-valued number and map it into a value between 0 and 1, but never exactly at those limits.

1 / (1 + e^-value)

Usage

import { LogisticRegression } from 'machinelearn/linear_model';
import { HeartDisease } from 'machinelearn/datasets';

(async function() {
  const { data, targets } = await heartDisease.load();
  const { xTest, xTrain, yTest } = train_test_split(data, targets);

  const lr = new LogisticRegression();
  lr.fit(xTrain, yTrain);

  lr.predict(yTest);
});

Constructors

Methods

Constructors


constructor

new LogisticRegression(__namedParameters: `object`)

Defined in linear_model/logistic_regression.ts:36

Parameters:

ParamTypeDefaultDescription
options.learning_ratenumber0.001Model learning rate
options.num_iterationsnumber4000Number of iterations to run gradient descent fo

Returns: LogisticRegression

Methods


λ fit

Fit the model according to the given training data.

Defined in linear_model/logistic_regression.ts:63

Parameters:

ParamTypeDefaultDescription
Xnumber[][] or number[]nullA matrix of samples
ynumber[]nullA matrix of targets

Returns:

void

λ fromJSON

Restore the model from a checkpoint

Defined in linear_model/logistic_regression.ts:114

Parameters:

ParamTypeDefaultDescription
options.learning_ratenumbernullModel learning rate
options.weightsnumber[]nullModel training weights

Returns:

void

λ predict

Predict class labels for samples in X.

Defined in linear_model/logistic_regression.ts:83

Parameters:

ParamTypeDefaultDescription
Xnumber[][] or number[]nullA matrix of test data

Returns:

number[]

λ toJSON

Get the model details in JSON format

Defined in linear_model/logistic_regression.ts:95

Returns:

ParamTypeDescription
learning_ratenumberModel learning rate
weightsnumber[]Model training weights