linear_model.SGDRegressor

Linear model fitted by minimizing a regularized empirical loss with SGD SGD stands for Stochastic Gradient Descent: 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).

Usage

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

Constructors

Methods

Constructors


constructor

new SGDRegressor(__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: SGDRegressor

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

Defined in linear_model/stochastic_gradient.ts:294

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