linear_model.Ridge

Linear least squares with l2 regularization. Mizimizes the objective function:

||y - Xw||^2_2 + alpha * ||w||^2_2

This model solves a regression model where the loss function is the linear least squares function and regularization is given by the l2-norm. Also known as Ridge Regression or Tikhonov regularization. This estimator has built-in support for multi-variate regression (i.e., when y is a 2d-array of shape [n_samples, n_targets]).

Usage

import { Iris } from 'machinelearn/datasets';
import { Ridge } from 'machinelearn/linear_model';
(async function() {
  const irisData = new Iris();
  const {
    data,         // returns the iris data (X)
    targets,      // list of target values (y)
  } = await irisData.load(); // loads the data internally

  const reg = new Ridge({ l2: 1 });
  reg.fit(data, target);
  reg.predict([[5.1,3.5,1.4,0.2]]);
})();

Constructors

Methods

Constructors


constructor

new Ridge(__namedParameters: `object`)

Defined in linear_model/coordinate_descent.ts:35

Parameters:

ParamTypeDefaultDescription
options.epochsnumber1000Number of epochs
options.l2numbernullRegularizer factor
options.learning_ratenumber0.001learning rate

Returns: Ridge

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