ridgefit

Linear regression with L2 regularization.

Syntax

parameters = ridgefit(X,y)

parameters = ridgefit(X,y,options)

Inputs

X
Training data.
Type: double
Dimension: vector | matrix
y
Target values.
Type: double
Dimension: vector | matrix
options
Type: struct
to_normalize
If true, input data X will be normalized before performing regression (default: false). It is done by subtracting mean and dividing by the standard deviation.
Type: Boolean
Dimension: logical
l2_penalty
Regularization Strength (default: 0). If value greater than 0, it becomes Ridge Regression.
Type: double | integer
Dimension: scalar

Outputs

parameters
Contains all the values passed to ridgefit 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
Estimated intercept.
Type: integer
Dimension: scalar
coef
Estimated coefficients
Type: double
Dimension: vector
params
Contains both intercept and coef as a vector. It is used by predict method.
Type: double
Dimension: vector
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 ridgefit 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.to_normalize = true;
options.l2_penalty = 0.03;
parameters = ridgefit(X, y, options);
> parameters
parameters = struct [
  coef: [Matrix] 3 x 1
  0.66572
  0.66572
  0.66572
  intercept: 4
  l2_penalty: 0.03
  n_features: 3
  n_samples: 7
  params: [Matrix] 4 x 1
  4.00000
  0.66572
  0.66572
  0.66572
  scorer: @r2
  to_normalize: 1
]

Comments

Output 'parameters' can be passed to ridgepredict function.