linear_model.Lasso

Linear Model trained with L1 prior as regularizer (aka the Lasso) The optimization objective for Lasso is:

(1 / (2 * n_samples)) * ||y - Xw||^2_2 + alpha * ||w||_1

Technically the Lasso model is optimizing the same objective function as the Elastic Net with l1_ratio value (no L2 penalty).

Usage

import { Iris } from 'machinelearn/datasets';
import { Lasso } 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 Lasso({ degree: 2, l1: 1 });
  reg.fit(data, target);
  reg.predict([[5.1,3.5,1.4,0.2]]);
})();

Constructors

Methods

Constructors


constructor

new Lasso(__namedParameters: `object`)

Defined in linear_model/coordinate_descent.ts:94

Parameters:

ParamTypeDefaultDescription
options.degreenumbernullPolynomial feature extraction degree
options.epochsnumber1000Number of epochs
options.l1numberRegularizer factor
options.learningratenumber0.001Learning rate

Returns: Lasso

Methods


λ fit

Fit model with coordinate descent.

Defined in linear_model/coordinate_descent.ts:140

Parameters:

ParamTypeDefaultDescription
Xnumber[][]nullA matrix of samples
ynumber[]nullA vector of targets

Returns:

void

λ fromJSON

Restore the model from a checkpoint

Defined in linear_model/stochastic_gradient.ts:151

Parameters:

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

Returns:

void

λ predict

Predict using the linear model

Defined in linear_model/coordinate_descent.ts:153

Parameters:

ParamTypeDefaultDescription
Xnumber[][]nullA matrix of test data

Returns:

number[]

λ toJSON

Save the model's checkpoint

Defined in linear_model/stochastic_gradient.ts:118

Returns:

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