linear_model.SGDClassifier

Linear classifiers (SVM, logistic regression, a.o.) with SGD training. This estimator implements regularized linear models with stochastic gradient descent (SGD) learning: the gradient of the loss is estimated each sample at a time and the model is updated along the way with a decreasing strength schedule (aka learning rate). SGD allows minibatch (online/out-of-core) learning, see the partial_fit method. For best results using the default learning rate schedule, the data should have zero mean and unit variance.

Usage

import { SGDClassifier } from 'machinelearn/linear_model';
const clf = new SGDClassifier();
const X = [[0., 0.], [1., 1.]];
const y = [0, 1];
clf.fit(X ,y);
clf.predict([[2., 2.]]); // result: [ 1 ]

Constructors

Methods

Constructors


constructor

new SGDClassifier(__namedParameters: `object`)

Defined in linear_model/stochastic_gradient.ts:33

Parameters:

ParamTypeDefaultDescription
options.clonebooleantrueTo clone the passed in dataset.
options.epochsnumber10000Number of iterations.
options.learning_ratenumber0.0001Used to limit the amount each coefficient is corrected each time it is updated.
options.lossstringTypeLoss.L2
options.random_statenumbernull
reg_factor.l1number
reg_factor.l2number

Returns: SGDClassifier

Methods


λ fit

Train the base SGD

Defined in linear_model/stochastic_gradient.ts:102

Parameters:

ParamTypeDefaultDescription
Xnumber[][]nullMatrix of data
ynumber[]nullMatrix of targets

Returns:

void

λ fromJSON

Restore the model from a checkpoint

Defined in linear_model/stochastic_gradient.ts:148

Parameters:

ParamTypeDefaultDescription
options.epochsnumber10000Number of model's training epochs
options.learning_ratenumber0.0001Training learning rate
options.random_statenumbernullStatic random state for the model initialization
options.weightsnumber[][]Model's training state

Returns:

void

λ predict

Predicted values with Math.round applied

Defined in linear_model/stochastic_gradient.ts:268

Parameters:

ParamTypeDefaultDescription
Xnumber[][]nullMatrix of data

Returns:

number[]

λ toJSON

Save the model's checkpoint

Defined in linear_model/stochastic_gradient.ts:115

Returns:

ParamTypeDescription
epochsnumbermodel training epochs
learning_ratenumbermodel learning rate
random_statenumberNumber used to set a static random state
weightsnumber[]Model training weights