Categories &

Functions List

Class Definition: ClassificationLinear

statistics: ClassificationLinear

Linear binary classifier for high dimensional data.

A ClassificationLinear object fits a linear model, X * Beta + Bias, to a two class problem by minimizing a regularized average loss. The loss is the hinge loss for a support vector machine and the deviance for a logistic regression, and the penalty is either a ridge or a lasso one.

Unlike the other classifiers of this package the object holds no copy of the training data: the coefficients, the intercept and the fitting options are the whole model. That is what makes it suited to data with more predictors than an in memory kernel matrix could carry, and it is why the class has no compact method and no resubstitution methods.

A vector of regularization strengths fits one model per value in a single object. Beta is then a PxL matrix and Bias a 1xL row, every method returns one column per strength, and selectModels narrows the object down to the strengths worth keeping.

Create a ClassificationLinear object with fitclinear.

See also: fitclinear, ClassificationKernel, ClassificationSVM

Source Code: ClassificationLinear

The ClassificationLinear class contains the following properties:

A column of the same type as the response supplied to the constructor: a cell array of character vectors, a numeric vector, a logical vector or a character matrix. The second of the two is the positive class, the one a positive score belongs to. This property is read-only.

Separate the two overlapping iris species with a linear classifier and read the posterior probability it gives each observation.

 load fisheriris
 X = meas(51:end,:);
 Y = species(51:end);
 Mdl = ClassificationLinear (X, Y, 'Learner', 'logistic')
Mdl =

  ClassificationLinear

             ResponseName: 'Y'
               ClassNames: {'versicolor'  'virginica'}
           ScoreTransform: 'logit'
                     Beta: [4x1 double]
                     Bias: -14.4308
                   Lambda: 0.01
                  Learner: 'logistic'
 [label, score] = predict (Mdl, X([1, 51],:))
label =
  2x1 cell array

    {'versicolor'}    
    {'virginica' }    

score =

   8.4236e-01   1.5764e-01
   6.5754e-03   9.9342e-01

One object can hold a whole regularization path. A stronger penalty shrinks the coefficients, and every method reports one column per strength.

 load fisheriris
 X = meas(51:end,:);
 Y = species(51:end);
 Mdl = ClassificationLinear (X, Y, 'Lambda', [0.001, 0.01, 0.1]);
 Mdl.Beta
ans =

  -1.033428  -1.032292  -0.092749
  -1.033597  -1.032989  -0.197723
   2.573697   2.574239   1.241068
   5.262861   5.262356   0.988460
 loss (Mdl, X, Y)
ans =

   0.030000   0.040000   0.050000

A numeric row vector with one element per class, in the order of ClassNames and summing to one. It defaults to the class frequencies of the training data. This property is read-only.

Separate the two overlapping iris species with a linear classifier and read the posterior probability it gives each observation.

 load fisheriris
 X = meas(51:end,:);
 Y = species(51:end);
 Mdl = ClassificationLinear (X, Y, 'Learner', 'logistic')
Mdl =

  ClassificationLinear

             ResponseName: 'Y'
               ClassNames: {'versicolor'  'virginica'}
           ScoreTransform: 'logit'
                     Beta: [4x1 double]
                     Bias: -14.4308
                   Lambda: 0.01
                  Learner: 'logistic'
 [label, score] = predict (Mdl, X([1, 51],:))
label =
  2x1 cell array

    {'versicolor'}    
    {'virginica' }    

score =

   8.4236e-01   1.5764e-01
   6.5754e-03   9.9342e-01

One object can hold a whole regularization path. A stronger penalty shrinks the coefficients, and every method reports one column per strength.

 load fisheriris
 X = meas(51:end,:);
 Y = species(51:end);
 Mdl = ClassificationLinear (X, Y, 'Lambda', [0.001, 0.01, 0.1]);
 Mdl.Beta
ans =

  -1.033428  -1.032292  -0.092749
  -1.033597  -1.032989  -0.197723
   2.573697   2.574239   1.241068
   5.262861   5.262356   0.988460
 loss (Mdl, X, Y)
ans =

   0.030000   0.040000   0.050000

A square numeric matrix with one row and one column per class, whose (i,j) element is the cost of classifying an observation of class i into class j. It defaults to one everywhere except the diagonal, which is zero. This property is read-only: MATLAB refuses an assignment into it on this class, as it does on the support vector machine, so a cost matrix is given to the constructor instead.

The cost matrix takes no part in the fit and none in predict, which returns the class of largest score. It is read by the 'mincost' and 'classifcost' losses alone.

Separate the two overlapping iris species with a linear classifier and read the posterior probability it gives each observation.

 load fisheriris
 X = meas(51:end,:);
 Y = species(51:end);
 Mdl = ClassificationLinear (X, Y, 'Learner', 'logistic')
Mdl =

  ClassificationLinear

             ResponseName: 'Y'
               ClassNames: {'versicolor'  'virginica'}
           ScoreTransform: 'logit'
                     Beta: [4x1 double]
                     Bias: -14.4308
                   Lambda: 0.01
                  Learner: 'logistic'
 [label, score] = predict (Mdl, X([1, 51],:))
label =
  2x1 cell array

    {'versicolor'}    
    {'virginica' }    

score =

   8.4236e-01   1.5764e-01
   6.5754e-03   9.9342e-01

One object can hold a whole regularization path. A stronger penalty shrinks the coefficients, and every method reports one column per strength.

 load fisheriris
 X = meas(51:end,:);
 Y = species(51:end);
 Mdl = ClassificationLinear (X, Y, 'Lambda', [0.001, 0.01, 0.1]);
 Mdl.Beta
ans =

  -1.033428  -1.032292  -0.092749
  -1.033597  -1.032989  -0.197723
   2.573697   2.574239   1.241068
   5.262861   5.262356   0.988460
 loss (Mdl, X, Y)
ans =

   0.030000   0.040000   0.050000

A character vector naming a transformation, or the text of the function handle that was supplied. Assigning to it accepts either. It defaults to 'logit' for a logistic learner, which turns the scores into posterior probabilities, and to 'none' for a support vector machine.

Separate the two overlapping iris species with a linear classifier and read the posterior probability it gives each observation.

 load fisheriris
 X = meas(51:end,:);
 Y = species(51:end);
 Mdl = ClassificationLinear (X, Y, 'Learner', 'logistic')
Mdl =

  ClassificationLinear

             ResponseName: 'Y'
               ClassNames: {'versicolor'  'virginica'}
           ScoreTransform: 'logit'
                     Beta: [4x1 double]
                     Bias: -14.4308
                   Lambda: 0.01
                  Learner: 'logistic'
 [label, score] = predict (Mdl, X([1, 51],:))
label =
  2x1 cell array

    {'versicolor'}    
    {'virginica' }    

score =

   8.4236e-01   1.5764e-01
   6.5754e-03   9.9342e-01

One object can hold a whole regularization path. A stronger penalty shrinks the coefficients, and every method reports one column per strength.

 load fisheriris
 X = meas(51:end,:);
 Y = species(51:end);
 Mdl = ClassificationLinear (X, Y, 'Lambda', [0.001, 0.01, 0.1]);
 Mdl.Beta
ans =

  -1.033428  -1.032292  -0.092749
  -1.033597  -1.032989  -0.197723
   2.573697   2.574239   1.241068
   5.262861   5.262356   0.988460
 loss (Mdl, X, Y)
ans =

   0.030000   0.040000   0.050000

A cell array of character vectors with one name per column of the training data, defaulting to 'x1', 'x2' and so on. This property is read-only.

Separate the two overlapping iris species with a linear classifier and read the posterior probability it gives each observation.

 load fisheriris
 X = meas(51:end,:);
 Y = species(51:end);
 Mdl = ClassificationLinear (X, Y, 'Learner', 'logistic')
Mdl =

  ClassificationLinear

             ResponseName: 'Y'
               ClassNames: {'versicolor'  'virginica'}
           ScoreTransform: 'logit'
                     Beta: [4x1 double]
                     Bias: -14.4308
                   Lambda: 0.01
                  Learner: 'logistic'
 [label, score] = predict (Mdl, X([1, 51],:))
label =
  2x1 cell array

    {'versicolor'}    
    {'virginica' }    

score =

   8.4236e-01   1.5764e-01
   6.5754e-03   9.9342e-01

One object can hold a whole regularization path. A stronger penalty shrinks the coefficients, and every method reports one column per strength.

 load fisheriris
 X = meas(51:end,:);
 Y = species(51:end);
 Mdl = ClassificationLinear (X, Y, 'Lambda', [0.001, 0.01, 0.1]);
 Mdl.Beta
ans =

  -1.033428  -1.032292  -0.092749
  -1.033597  -1.032989  -0.197723
   2.573697   2.574239   1.241068
   5.262861   5.262356   0.988460
 loss (Mdl, X, Y)
ans =

   0.030000   0.040000   0.050000

A row vector of column indices, empty when every predictor is numeric. This property is read-only.

Separate the two overlapping iris species with a linear classifier and read the posterior probability it gives each observation.

 load fisheriris
 X = meas(51:end,:);
 Y = species(51:end);
 Mdl = ClassificationLinear (X, Y, 'Learner', 'logistic')
Mdl =

  ClassificationLinear

             ResponseName: 'Y'
               ClassNames: {'versicolor'  'virginica'}
           ScoreTransform: 'logit'
                     Beta: [4x1 double]
                     Bias: -14.4308
                   Lambda: 0.01
                  Learner: 'logistic'
 [label, score] = predict (Mdl, X([1, 51],:))
label =
  2x1 cell array

    {'versicolor'}    
    {'virginica' }    

score =

   8.4236e-01   1.5764e-01
   6.5754e-03   9.9342e-01

One object can hold a whole regularization path. A stronger penalty shrinks the coefficients, and every method reports one column per strength.

 load fisheriris
 X = meas(51:end,:);
 Y = species(51:end);
 Mdl = ClassificationLinear (X, Y, 'Lambda', [0.001, 0.01, 0.1]);
 Mdl.Beta
ans =

  -1.033428  -1.032292  -0.092749
  -1.033597  -1.032989  -0.197723
   2.573697   2.574239   1.241068
   5.262861   5.262356   0.988460
 loss (Mdl, X, Y)
ans =

   0.030000   0.040000   0.050000

A character vector, defaulting to 'Y'. This property is read-only.

Separate the two overlapping iris species with a linear classifier and read the posterior probability it gives each observation.

 load fisheriris
 X = meas(51:end,:);
 Y = species(51:end);
 Mdl = ClassificationLinear (X, Y, 'Learner', 'logistic')
Mdl =

  ClassificationLinear

             ResponseName: 'Y'
               ClassNames: {'versicolor'  'virginica'}
           ScoreTransform: 'logit'
                     Beta: [4x1 double]
                     Bias: -14.4308
                   Lambda: 0.01
                  Learner: 'logistic'
 [label, score] = predict (Mdl, X([1, 51],:))
label =
  2x1 cell array

    {'versicolor'}    
    {'virginica' }    

score =

   8.4236e-01   1.5764e-01
   6.5754e-03   9.9342e-01

One object can hold a whole regularization path. A stronger penalty shrinks the coefficients, and every method reports one column per strength.

 load fisheriris
 X = meas(51:end,:);
 Y = species(51:end);
 Mdl = ClassificationLinear (X, Y, 'Lambda', [0.001, 0.01, 0.1]);
 Mdl.Beta
ans =

  -1.033428  -1.032292  -0.092749
  -1.033597  -1.032989  -0.197723
   2.573697   2.574239   1.241068
   5.262861   5.262356   0.988460
 loss (Mdl, X, Y)
ans =

   0.030000   0.040000   0.050000

A cell array of character vectors. It equals PredictorNames unless categorical predictors were expanded into indicator variables. This property is read-only.

Separate the two overlapping iris species with a linear classifier and read the posterior probability it gives each observation.

 load fisheriris
 X = meas(51:end,:);
 Y = species(51:end);
 Mdl = ClassificationLinear (X, Y, 'Learner', 'logistic')
Mdl =

  ClassificationLinear

             ResponseName: 'Y'
               ClassNames: {'versicolor'  'virginica'}
           ScoreTransform: 'logit'
                     Beta: [4x1 double]
                     Bias: -14.4308
                   Lambda: 0.01
                  Learner: 'logistic'
 [label, score] = predict (Mdl, X([1, 51],:))
label =
  2x1 cell array

    {'versicolor'}    
    {'virginica' }    

score =

   8.4236e-01   1.5764e-01
   6.5754e-03   9.9342e-01

One object can hold a whole regularization path. A stronger penalty shrinks the coefficients, and every method reports one column per strength.

 load fisheriris
 X = meas(51:end,:);
 Y = species(51:end);
 Mdl = ClassificationLinear (X, Y, 'Lambda', [0.001, 0.01, 0.1]);
 Mdl.Beta
ans =

  -1.033428  -1.032292  -0.092749
  -1.033597  -1.032989  -0.197723
   2.573697   2.574239   1.241068
   5.262861   5.262356   0.988460
 loss (Mdl, X, Y)
ans =

   0.030000   0.040000   0.050000

Either 'svm' or 'logistic'. This property is read-only.

Separate the two overlapping iris species with a linear classifier and read the posterior probability it gives each observation.

 load fisheriris
 X = meas(51:end,:);
 Y = species(51:end);
 Mdl = ClassificationLinear (X, Y, 'Learner', 'logistic')
Mdl =

  ClassificationLinear

             ResponseName: 'Y'
               ClassNames: {'versicolor'  'virginica'}
           ScoreTransform: 'logit'
                     Beta: [4x1 double]
                     Bias: -14.4308
                   Lambda: 0.01
                  Learner: 'logistic'
 [label, score] = predict (Mdl, X([1, 51],:))
label =
  2x1 cell array

    {'versicolor'}    
    {'virginica' }    

score =

   8.4236e-01   1.5764e-01
   6.5754e-03   9.9342e-01

One object can hold a whole regularization path. A stronger penalty shrinks the coefficients, and every method reports one column per strength.

 load fisheriris
 X = meas(51:end,:);
 Y = species(51:end);
 Mdl = ClassificationLinear (X, Y, 'Lambda', [0.001, 0.01, 0.1]);
 Mdl.Beta
ans =

  -1.033428  -1.032292  -0.092749
  -1.033597  -1.032989  -0.197723
   2.573697   2.574239   1.241068
   5.262861   5.262356   0.988460
 loss (Mdl, X, Y)
ans =

   0.030000   0.040000   0.050000

A Px1 column, or a PxL matrix with one column per regularization strength when Lambda holds more than one. This property is read-only.

Separate the two overlapping iris species with a linear classifier and read the posterior probability it gives each observation.

 load fisheriris
 X = meas(51:end,:);
 Y = species(51:end);
 Mdl = ClassificationLinear (X, Y, 'Learner', 'logistic')
Mdl =

  ClassificationLinear

             ResponseName: 'Y'
               ClassNames: {'versicolor'  'virginica'}
           ScoreTransform: 'logit'
                     Beta: [4x1 double]
                     Bias: -14.4308
                   Lambda: 0.01
                  Learner: 'logistic'
 [label, score] = predict (Mdl, X([1, 51],:))
label =
  2x1 cell array

    {'versicolor'}    
    {'virginica' }    

score =

   8.4236e-01   1.5764e-01
   6.5754e-03   9.9342e-01

One object can hold a whole regularization path. A stronger penalty shrinks the coefficients, and every method reports one column per strength.

 load fisheriris
 X = meas(51:end,:);
 Y = species(51:end);
 Mdl = ClassificationLinear (X, Y, 'Lambda', [0.001, 0.01, 0.1]);
 Mdl.Beta
ans =

  -1.033428  -1.032292  -0.092749
  -1.033597  -1.032989  -0.197723
   2.573697   2.574239   1.241068
   5.262861   5.262356   0.988460
 loss (Mdl, X, Y)
ans =

   0.030000   0.040000   0.050000

A scalar, or a 1xL row with one element per regularization strength. It is zero throughout when the model was fitted with 'FitBias' set to false. This property is read-only.

Separate the two overlapping iris species with a linear classifier and read the posterior probability it gives each observation.

 load fisheriris
 X = meas(51:end,:);
 Y = species(51:end);
 Mdl = ClassificationLinear (X, Y, 'Learner', 'logistic')
Mdl =

  ClassificationLinear

             ResponseName: 'Y'
               ClassNames: {'versicolor'  'virginica'}
           ScoreTransform: 'logit'
                     Beta: [4x1 double]
                     Bias: -14.4308
                   Lambda: 0.01
                  Learner: 'logistic'
 [label, score] = predict (Mdl, X([1, 51],:))
label =
  2x1 cell array

    {'versicolor'}    
    {'virginica' }    

score =

   8.4236e-01   1.5764e-01
   6.5754e-03   9.9342e-01

One object can hold a whole regularization path. A stronger penalty shrinks the coefficients, and every method reports one column per strength.

 load fisheriris
 X = meas(51:end,:);
 Y = species(51:end);
 Mdl = ClassificationLinear (X, Y, 'Lambda', [0.001, 0.01, 0.1]);
 Mdl.Beta
ans =

  -1.033428  -1.032292  -0.092749
  -1.033597  -1.032989  -0.197723
   2.573697   2.574239   1.241068
   5.262861   5.262356   0.988460
 loss (Mdl, X, Y)
ans =

   0.030000   0.040000   0.050000

'hinge' for a support vector machine and 'logit' for a logistic regression. This is the loss of the objective, which is not the loss loss reports unless it is asked for. This property is read-only.

Separate the two overlapping iris species with a linear classifier and read the posterior probability it gives each observation.

 load fisheriris
 X = meas(51:end,:);
 Y = species(51:end);
 Mdl = ClassificationLinear (X, Y, 'Learner', 'logistic')
Mdl =

  ClassificationLinear

             ResponseName: 'Y'
               ClassNames: {'versicolor'  'virginica'}
           ScoreTransform: 'logit'
                     Beta: [4x1 double]
                     Bias: -14.4308
                   Lambda: 0.01
                  Learner: 'logistic'
 [label, score] = predict (Mdl, X([1, 51],:))
label =
  2x1 cell array

    {'versicolor'}    
    {'virginica' }    

score =

   8.4236e-01   1.5764e-01
   6.5754e-03   9.9342e-01

One object can hold a whole regularization path. A stronger penalty shrinks the coefficients, and every method reports one column per strength.

 load fisheriris
 X = meas(51:end,:);
 Y = species(51:end);
 Mdl = ClassificationLinear (X, Y, 'Lambda', [0.001, 0.01, 0.1]);
 Mdl.Beta
ans =

  -1.033428  -1.032292  -0.092749
  -1.033597  -1.032989  -0.197723
   2.573697   2.574239   1.241068
   5.262861   5.262356   0.988460
 loss (Mdl, X, Y)
ans =

   0.030000   0.040000   0.050000

A nonnegative scalar, or a 1xL row of them in ascending order. It defaults to the reciprocal of the number of observations used to train the model. This property is read-only.

Separate the two overlapping iris species with a linear classifier and read the posterior probability it gives each observation.

 load fisheriris
 X = meas(51:end,:);
 Y = species(51:end);
 Mdl = ClassificationLinear (X, Y, 'Learner', 'logistic')
Mdl =

  ClassificationLinear

             ResponseName: 'Y'
               ClassNames: {'versicolor'  'virginica'}
           ScoreTransform: 'logit'
                     Beta: [4x1 double]
                     Bias: -14.4308
                   Lambda: 0.01
                  Learner: 'logistic'
 [label, score] = predict (Mdl, X([1, 51],:))
label =
  2x1 cell array

    {'versicolor'}    
    {'virginica' }    

score =

   8.4236e-01   1.5764e-01
   6.5754e-03   9.9342e-01

One object can hold a whole regularization path. A stronger penalty shrinks the coefficients, and every method reports one column per strength.

 load fisheriris
 X = meas(51:end,:);
 Y = species(51:end);
 Mdl = ClassificationLinear (X, Y, 'Lambda', [0.001, 0.01, 0.1]);
 Mdl.Beta
ans =

  -1.033428  -1.032292  -0.092749
  -1.033597  -1.032989  -0.197723
   2.573697   2.574239   1.241068
   5.262861   5.262356   0.988460
 loss (Mdl, X, Y)
ans =

   0.030000   0.040000   0.050000

A structure holding every parameter of the fit, including the ones that a different solver would have used and the 'auto' values before they were resolved. This property is read-only.

Separate the two overlapping iris species with a linear classifier and read the posterior probability it gives each observation.

 load fisheriris
 X = meas(51:end,:);
 Y = species(51:end);
 Mdl = ClassificationLinear (X, Y, 'Learner', 'logistic')
Mdl =

  ClassificationLinear

             ResponseName: 'Y'
               ClassNames: {'versicolor'  'virginica'}
           ScoreTransform: 'logit'
                     Beta: [4x1 double]
                     Bias: -14.4308
                   Lambda: 0.01
                  Learner: 'logistic'
 [label, score] = predict (Mdl, X([1, 51],:))
label =
  2x1 cell array

    {'versicolor'}    
    {'virginica' }    

score =

   8.4236e-01   1.5764e-01
   6.5754e-03   9.9342e-01

One object can hold a whole regularization path. A stronger penalty shrinks the coefficients, and every method reports one column per strength.

 load fisheriris
 X = meas(51:end,:);
 Y = species(51:end);
 Mdl = ClassificationLinear (X, Y, 'Lambda', [0.001, 0.01, 0.1]);
 Mdl.Beta
ans =

  -1.033428  -1.032292  -0.092749
  -1.033597  -1.032989  -0.197723
   2.573697   2.574239   1.241068
   5.262861   5.262356   0.988460
 loss (Mdl, X, Y)
ans =

   0.030000   0.040000   0.050000

'ridge (L2)' or 'lasso (L1)'. This property is read-only.

Separate the two overlapping iris species with a linear classifier and read the posterior probability it gives each observation.

 load fisheriris
 X = meas(51:end,:);
 Y = species(51:end);
 Mdl = ClassificationLinear (X, Y, 'Learner', 'logistic')
Mdl =

  ClassificationLinear

             ResponseName: 'Y'
               ClassNames: {'versicolor'  'virginica'}
           ScoreTransform: 'logit'
                     Beta: [4x1 double]
                     Bias: -14.4308
                   Lambda: 0.01
                  Learner: 'logistic'
 [label, score] = predict (Mdl, X([1, 51],:))
label =
  2x1 cell array

    {'versicolor'}    
    {'virginica' }    

score =

   8.4236e-01   1.5764e-01
   6.5754e-03   9.9342e-01

One object can hold a whole regularization path. A stronger penalty shrinks the coefficients, and every method reports one column per strength.

 load fisheriris
 X = meas(51:end,:);
 Y = species(51:end);
 Mdl = ClassificationLinear (X, Y, 'Lambda', [0.001, 0.01, 0.1]);
 Mdl.Beta
ans =

  -1.033428  -1.032292  -0.092749
  -1.033597  -1.032989  -0.197723
   2.573697   2.574239   1.241068
   5.262861   5.262356   0.988460
 loss (Mdl, X, Y)
ans =

   0.030000   0.040000   0.050000

The ClassificationLinear class offers the following public methods:

ClassificationLinear: obj = ClassificationLinear (X, Y)
ClassificationLinear: obj = ClassificationLinear (…, name, value)

obj = ClassificationLinear (X, Y) fits a linear support vector machine to the NxP predictor matrix X and the Nx1 response Y, which must name exactly two classes.

obj = ClassificationLinear (…, name, value) takes the following Name-Value pairs.

NameValue
'Learner''svm', the default, or 'logistic'. The first minimizes the hinge loss and the second the deviance.
'Regularization''ridge' or 'lasso'. It defaults to 'lasso' when the solver is 'sparsa' and to 'ridge' otherwise.
'Lambda''auto', the default, which is the reciprocal of the number of observations, or a nonnegative scalar, or a vector of them. A vector fits one model per value.
'Solver'One of 'sgd', 'asgd', 'dual', 'bfgs', 'lbfgs' and 'sparsa', or a cell array of them applied in turn, each warm starting the next. The default depends on the data and the penalty, as described below.
'Beta'Initial coefficients, a Px1 column or a PxL matrix. It defaults to zeros.
'Bias'Initial intercept, a scalar or a 1xL row. It defaults to the weighted average of the class labels for a logistic learner and to zero for a support vector machine.
'FitBias'Whether to fit an intercept at all, true by default.
'PostFitBias'Whether to refit the intercept once the coefficients are settled, false by default.
'ObservationsIn''rows', the default, or 'columns', which transposes X before fitting.
'BetaTolerance'Relative tolerance on the coefficients, 1e-4 by default.
'GradientTolerance'Absolute tolerance on the gradient’s infinity norm, 1e-6 by default.
'DeltaGradientTolerance'Tolerance on the complementarity gap of the 'dual' solver, 1 by default for a hinge loss. MathWorks documents 0.1, which is the default of the regression counterpart; R2024a and R2026a both report 1 here.
'IterationLimit'Largest number of iterations, 1000 by default.
'PassLimit'Largest number of passes over the data for the stochastic solvers, 1 by default, and 10 for 'dual'.
'BatchSize'Mini-batch size of the stochastic solvers, 10 by default.
'BatchLimit'Largest number of mini-batches.
'LearnRate'Step size of the stochastic solvers.
'OptimizeLearnRate'Whether to halve the step size when the objective rises, true by default.
'TruncationPeriod'Number of mini-batches between soft thresholdings under a lasso penalty, 10 by default.
'NumCheckConvergence'Number of passes between convergence checks of the 'dual' solver, 2 by default. MathWorks documents 5; R2024a and R2026a both report 2, so the documentation is stale rather than the releases being inconsistent.
'HessianHistorySize'Number of curvature pairs the quasi-Newton solvers keep, 15 by default.
'ClassNames'The classes to keep, given in the type of Y. Observations of any other class are dropped.
'Cost'A square misclassification cost matrix.
'Prior''empirical', the default, 'uniform', a vector of probabilities, or a structure with ClassNames and ClassProbs fields.
'ScoreTransform'A transformation applied to the scores, named or given as a function handle.
'Weights'One nonnegative weight per observation.
'PredictorNames'One name per predictor.
'ResponseName'A name for the response.
'CategoricalPredictors'Indices of the categorical predictors.

The default solver is 'sparsa' under a lasso penalty. Under a ridge penalty it is 'bfgs' when there are no more than 100 predictors, and beyond that 'dual' for a support vector machine and 'sgd' for a logistic regression.

See also: fitclinear, ClassificationKernel

Separate the two overlapping iris species with a linear classifier and read the posterior probability it gives each observation.

 load fisheriris
 X = meas(51:end,:);
 Y = species(51:end);
 Mdl = ClassificationLinear (X, Y, 'Learner', 'logistic')
Mdl =

  ClassificationLinear

             ResponseName: 'Y'
               ClassNames: {'versicolor'  'virginica'}
           ScoreTransform: 'logit'
                     Beta: [4x1 double]
                     Bias: -14.4308
                   Lambda: 0.01
                  Learner: 'logistic'
 [label, score] = predict (Mdl, X([1, 51],:))
label =
  2x1 cell array

    {'versicolor'}    
    {'virginica' }    

score =

   8.4236e-01   1.5764e-01
   6.5754e-03   9.9342e-01

One object can hold a whole regularization path. A stronger penalty shrinks the coefficients, and every method reports one column per strength.

 load fisheriris
 X = meas(51:end,:);
 Y = species(51:end);
 Mdl = ClassificationLinear (X, Y, 'Lambda', [0.001, 0.01, 0.1]);
 Mdl.Beta
ans =

  -1.033428  -1.032292  -0.092749
  -1.033597  -1.032989  -0.197723
   2.573697   2.574239   1.241068
   5.262861   5.262356   0.988460
 loss (Mdl, X, Y)
ans =

   0.030000   0.040000   0.050000
ClassificationLinear: labels = predict (obj, XC)
ClassificationLinear: [labels, scores] = predict (obj, XC)

labels = predict (obj, XC) returns the class of largest score for each row of XC, in the type of the response the model was fitted to. With L regularization strengths labels has one column per strength.

[labels, scores] = predict (obj, XC) also returns the scores, an Nx2 matrix whose columns follow ClassNames, or an Nx2xL array with more than one strength. The scores are -f and +f for the raw model value f, after ScoreTransform has been applied.

Separate the two overlapping iris species with a linear classifier and read the posterior probability it gives each observation.

 load fisheriris
 X = meas(51:end,:);
 Y = species(51:end);
 Mdl = ClassificationLinear (X, Y, 'Learner', 'logistic')
Mdl =

  ClassificationLinear

             ResponseName: 'Y'
               ClassNames: {'versicolor'  'virginica'}
           ScoreTransform: 'logit'
                     Beta: [4x1 double]
                     Bias: -14.4308
                   Lambda: 0.01
                  Learner: 'logistic'
 [label, score] = predict (Mdl, X([1, 51],:))
label =
  2x1 cell array

    {'versicolor'}    
    {'virginica' }    

score =

   8.4236e-01   1.5764e-01
   6.5754e-03   9.9342e-01

One object can hold a whole regularization path. A stronger penalty shrinks the coefficients, and every method reports one column per strength.

 load fisheriris
 X = meas(51:end,:);
 Y = species(51:end);
 Mdl = ClassificationLinear (X, Y, 'Lambda', [0.001, 0.01, 0.1]);
 Mdl.Beta
ans =

  -1.033428  -1.032292  -0.092749
  -1.033597  -1.032989  -0.197723
   2.573697   2.574239   1.241068
   5.262861   5.262356   0.988460
 loss (Mdl, X, Y)
ans =

   0.030000   0.040000   0.050000
ClassificationLinear: m = margin (obj, X, Y)

m = margin (obj, X, Y) returns the score of the true class less the score of the other one, one row per observation and one column per regularization strength. A positive margin is a correct classification.

Separate the two overlapping iris species with a linear classifier and read the posterior probability it gives each observation.

 load fisheriris
 X = meas(51:end,:);
 Y = species(51:end);
 Mdl = ClassificationLinear (X, Y, 'Learner', 'logistic')
Mdl =

  ClassificationLinear

             ResponseName: 'Y'
               ClassNames: {'versicolor'  'virginica'}
           ScoreTransform: 'logit'
                     Beta: [4x1 double]
                     Bias: -14.4308
                   Lambda: 0.01
                  Learner: 'logistic'
 [label, score] = predict (Mdl, X([1, 51],:))
label =
  2x1 cell array

    {'versicolor'}    
    {'virginica' }    

score =

   8.4236e-01   1.5764e-01
   6.5754e-03   9.9342e-01

One object can hold a whole regularization path. A stronger penalty shrinks the coefficients, and every method reports one column per strength.

 load fisheriris
 X = meas(51:end,:);
 Y = species(51:end);
 Mdl = ClassificationLinear (X, Y, 'Lambda', [0.001, 0.01, 0.1]);
 Mdl.Beta
ans =

  -1.033428  -1.032292  -0.092749
  -1.033597  -1.032989  -0.197723
   2.573697   2.574239   1.241068
   5.262861   5.262356   0.988460
 loss (Mdl, X, Y)
ans =

   0.030000   0.040000   0.050000
ClassificationLinear: e = edge (obj, X, Y)
ClassificationLinear: e = edge (…, 'Weights', W)

e = edge (obj, X, Y) returns one value per regularization strength. The weights are normalized within each class to that class’s prior before they are applied.

Separate the two overlapping iris species with a linear classifier and read the posterior probability it gives each observation.

 load fisheriris
 X = meas(51:end,:);
 Y = species(51:end);
 Mdl = ClassificationLinear (X, Y, 'Learner', 'logistic')
Mdl =

  ClassificationLinear

             ResponseName: 'Y'
               ClassNames: {'versicolor'  'virginica'}
           ScoreTransform: 'logit'
                     Beta: [4x1 double]
                     Bias: -14.4308
                   Lambda: 0.01
                  Learner: 'logistic'
 [label, score] = predict (Mdl, X([1, 51],:))
label =
  2x1 cell array

    {'versicolor'}    
    {'virginica' }    

score =

   8.4236e-01   1.5764e-01
   6.5754e-03   9.9342e-01

One object can hold a whole regularization path. A stronger penalty shrinks the coefficients, and every method reports one column per strength.

 load fisheriris
 X = meas(51:end,:);
 Y = species(51:end);
 Mdl = ClassificationLinear (X, Y, 'Lambda', [0.001, 0.01, 0.1]);
 Mdl.Beta
ans =

  -1.033428  -1.032292  -0.092749
  -1.033597  -1.032989  -0.197723
   2.573697   2.574239   1.241068
   5.262861   5.262356   0.988460
 loss (Mdl, X, Y)
ans =

   0.030000   0.040000   0.050000
ClassificationLinear: l = loss (obj, X, Y)
ClassificationLinear: l = loss (…, name, value)

l = loss (obj, X, Y) returns the misclassification rate, one value per regularization strength.

l = loss (…, name, value) takes 'LossFun', one of 'binodeviance', 'classifcost', 'classiferror', 'exponential', 'hinge', 'logit', 'mincost' and 'quadratic', and 'Weights'.

Separate the two overlapping iris species with a linear classifier and read the posterior probability it gives each observation.

 load fisheriris
 X = meas(51:end,:);
 Y = species(51:end);
 Mdl = ClassificationLinear (X, Y, 'Learner', 'logistic')
Mdl =

  ClassificationLinear

             ResponseName: 'Y'
               ClassNames: {'versicolor'  'virginica'}
           ScoreTransform: 'logit'
                     Beta: [4x1 double]
                     Bias: -14.4308
                   Lambda: 0.01
                  Learner: 'logistic'
 [label, score] = predict (Mdl, X([1, 51],:))
label =
  2x1 cell array

    {'versicolor'}    
    {'virginica' }    

score =

   8.4236e-01   1.5764e-01
   6.5754e-03   9.9342e-01

One object can hold a whole regularization path. A stronger penalty shrinks the coefficients, and every method reports one column per strength.

 load fisheriris
 X = meas(51:end,:);
 Y = species(51:end);
 Mdl = ClassificationLinear (X, Y, 'Lambda', [0.001, 0.01, 0.1]);
 Mdl.Beta
ans =

  -1.033428  -1.032292  -0.092749
  -1.033597  -1.032989  -0.197723
   2.573697   2.574239   1.241068
   5.262861   5.262356   0.988460
 loss (Mdl, X, Y)
ans =

   0.030000   0.040000   0.050000
ClassificationLinear: sub = selectModels (obj, idx)

sub = selectModels (obj, idx) returns a model holding only the strengths idx names, which may be indices into Lambda or a logical vector over it.

Separate the two overlapping iris species with a linear classifier and read the posterior probability it gives each observation.

 load fisheriris
 X = meas(51:end,:);
 Y = species(51:end);
 Mdl = ClassificationLinear (X, Y, 'Learner', 'logistic')
Mdl =

  ClassificationLinear

             ResponseName: 'Y'
               ClassNames: {'versicolor'  'virginica'}
           ScoreTransform: 'logit'
                     Beta: [4x1 double]
                     Bias: -14.4308
                   Lambda: 0.01
                  Learner: 'logistic'
 [label, score] = predict (Mdl, X([1, 51],:))
label =
  2x1 cell array

    {'versicolor'}    
    {'virginica' }    

score =

   8.4236e-01   1.5764e-01
   6.5754e-03   9.9342e-01

One object can hold a whole regularization path. A stronger penalty shrinks the coefficients, and every method reports one column per strength.

 load fisheriris
 X = meas(51:end,:);
 Y = species(51:end);
 Mdl = ClassificationLinear (X, Y, 'Lambda', [0.001, 0.01, 0.1]);
 Mdl.Beta
ans =

  -1.033428  -1.032292  -0.092749
  -1.033597  -1.032989  -0.197723
   2.573697   2.574239   1.241068
   5.262861   5.262356   0.988460
 loss (Mdl, X, Y)
ans =

   0.030000   0.040000   0.050000
ClassificationLinear: savemodel (obj, filename)

savemodel (obj, filename) saves the model obj into filename in a form loadmodel can read back.

Separate the two overlapping iris species with a linear classifier and read the posterior probability it gives each observation.

 load fisheriris
 X = meas(51:end,:);
 Y = species(51:end);
 Mdl = ClassificationLinear (X, Y, 'Learner', 'logistic')
Mdl =

  ClassificationLinear

             ResponseName: 'Y'
               ClassNames: {'versicolor'  'virginica'}
           ScoreTransform: 'logit'
                     Beta: [4x1 double]
                     Bias: -14.4308
                   Lambda: 0.01
                  Learner: 'logistic'
 [label, score] = predict (Mdl, X([1, 51],:))
label =
  2x1 cell array

    {'versicolor'}    
    {'virginica' }    

score =

   8.4236e-01   1.5764e-01
   6.5754e-03   9.9342e-01

One object can hold a whole regularization path. A stronger penalty shrinks the coefficients, and every method reports one column per strength.

 load fisheriris
 X = meas(51:end,:);
 Y = species(51:end);
 Mdl = ClassificationLinear (X, Y, 'Lambda', [0.001, 0.01, 0.1]);
 Mdl.Beta
ans =

  -1.033428  -1.032292  -0.092749
  -1.033597  -1.032989  -0.197723
   2.573697   2.574239   1.241068
   5.262861   5.262356   0.988460
 loss (Mdl, X, Y)
ans =

   0.030000   0.040000   0.050000

Examples

 load fisheriris
 X = meas(51:end,:);
 Y = species(51:end);
 Mdl = ClassificationLinear (X, Y, 'Learner', 'logistic')
Mdl =

  ClassificationLinear

             ResponseName: 'Y'
               ClassNames: {'versicolor'  'virginica'}
           ScoreTransform: 'logit'
                     Beta: [4x1 double]
                     Bias: -14.4308
                   Lambda: 0.01
                  Learner: 'logistic'
 [label, score] = predict (Mdl, X([1, 51],:))
label =
  2x1 cell array

    {'versicolor'}    
    {'virginica' }    

score =

   8.4236e-01   1.5764e-01
   6.5754e-03   9.9342e-01
 load fisheriris
 X = meas(51:end,:);
 Y = species(51:end);
 Mdl = ClassificationLinear (X, Y, 'Lambda', [0.001, 0.01, 0.1]);
 Mdl.Beta
ans =

  -1.033428  -1.032292  -0.092749
  -1.033597  -1.032989  -0.197723
   2.573697   2.574239   1.241068
   5.262861   5.262356   0.988460
 loss (Mdl, X, Y)
ans =

   0.030000   0.040000   0.050000