lassofit

Regression estimator. Linear Model trained with L1 regularization technique (Lasso).

Attention: Available only with Twin Activate commercial edition.

Syntax

parameters = lassofit(X,y)

parameters = lassofit(X,y,options)

Inputs

X
Training data.
Type: double
Dimension: vector | matrix
y
Target values.
Type: double
Dimension: vector | matrix
options
Type: struct
alpha
Constant that multiplies the L1 term (default: 1). Defaults to 1.0. If alpha=0, it’s equivalent to Ordinary Least Square. Instead of setting alpha=0, linearFit can be used.
Type: double
Dimension: scalar
normalize
If true, input data X will be normalized before performing regression (default: false). It’s done by subtracting mean and dividing by the standard deviation.
Type: Boolean
Dimension: logical
max_iter
Maximum number of iterations.
Type: integer
Dimension: scalar
tol
Tolerance for the optimization. If the updates are smaller than tol the optimization code checks the dual gap for optimality and continues until it is smaller than the tolerance.
Type: double
Dimension: scalar
positive
If set to true, forces the coefficients to be positive (default: false).
Type: Boolean
Dimension: logical
random_state
Selects a random feature to update. random_state is the seed used by the random number generator.
Type: integer
Dimension: scalar
selection
If set to 'random', a random coefficient is updated every iteration rather than looping over features sequentially. This ('random') often leads to significantly faster convergence especially when tol is higher than 1e-4. Default: 'cyclic'
Type: char
Dimension: string

Outputs

parameters
Contains all the values passed to lassofit method as options. Additionally it has below key-value pairs.
Type: struct
scorer
Function handle pointing to r2 function (R2 Coefficient of Determination).
Type: function handle
intercept
Constants in decision function.
Type: integer
Dimension: scalar
coef
Parameter vector.
Type: double
Dimension: n_features
params
Parameter vector with intercept.
Type: double
Dimension: n_features + 1
n_iter
Number of iterations run by the coordinate descent solver to reach the specified tolerance.
Type: integer
Dimension: scalar
n_samples
Number of rows in the training data.
Type: integer
Dimension: scalar
n_features
Number of columns in the training data.
Type: integer
Dimension: scalar

Example

Usage of lassofit with options

X = [1 2 3; 4 5 6; 7 8 9; 10 11 12; 13 14 15; 16 17 18; 19 20 21];
y = [1, 2, 3, 4, 5, 6, 7];
options = struct;
options.normalize = true;
parameters = lassofit(X, y, options)
parameters = struct [
  alpha: 1
  coef: [Matrix] 1 x 3
  0  0  0
  intercept: 4
  n_features: 3
  n_iter: 1
  n_samples: 7
  normalize: 1
  params: [Matrix] 1 x 4
  4  0  0  0
  positive: 0 
  scorer: @r2
  selection: cyclic
]

Comments

Coordinate descent is used to fit the model. Coordinate descent is an algorithm that considers each column of data at a time. Output 'parameters' can be passed to lassopredict function.