olsfit

Ordinary Least Squares Linear regression.

Attention: Available only with Twin Activate commercial edition.

Syntax

parameters = olsfit(X,y)

parameters = olsfit(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

Outputs

parameters
Contains all the values passed to olsfit 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 olsfit 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;
parameters = olsfit(X, y, options)
parameters = struct [
  coef: [Matrix] 3 x 1
  0.66667
  0.66667
  0.66667
  intercept: 4
  n_features: 3
  n_samples: 7
  params: [Matrix] 4 x 1
  4.00000
  0.66667
  0.66667
  0.66667
  scorer: @r2
  to_normalize: 1
] 

Comments

It performs regression using Ordinary Least Squares method. Once the coefficients are computed, outputs are predicted using olspredict method.