Categories &

Functions List

Class Definition: CompactClassificationSVM

statistics: CompactClassificationSVM

Compact Support Vector Machine classification

The CompactClassificationSVM class implements a compact version of a Support Vector Machine classifier object for one-class or two-class problems, which can predict responses for new data using the predict method.

A CompactClassificationSVM object is a compact version of a support vector machine model, ClassificationSVM. It does not include the training data resulting in a smaller classifier size, which can be used for making predictions from new data, but not for tasks such as cross validation. It can only be created from a ClassificationSVM model by using the compact object method.

See also: ClassificationSVM

Source Code: CompactClassificationSVM

The CompactClassificationSVM class contains the following properties:

A positive integer value specifying the number of predictors in the training dataset used for training the SVM model. This property is read-only.

Create a support vectors machine classifier and its compact version

 rng (42);

and compare their size

 load fisheriris
 X = meas;
 Y = species;
 selected_classes = unique (Y)(randperm (3, 2));
 selected_indices = ismember (Y, selected_classes);
 X_selected = X(selected_indices, :);
 Y_selected = Y(selected_indices);
 Mdl = fitcsvm (X_selected, Y_selected, 'ClassNames', selected_classes);
 CMdl = crossval (Mdl)
CMdl =

  ClassificationPartitionedModel

      CrossValidatedModel: 'SVM'
             ResponseName: 'Y'
               ClassNames: {'setosa' 'versicolor'}
          NumObservations: 100
                    KFold: 10
           ScoreTransform: 'none'

A cell array of character vectors specifying the names of the predictor variables. The names are in the order in which they appear in the training dataset. This property is read-only.

Create a support vectors machine classifier and its compact version

 rng (42);

and compare their size

 load fisheriris
 X = meas;
 Y = species;
 selected_classes = unique (Y)(randperm (3, 2));
 selected_indices = ismember (Y, selected_classes);
 X_selected = X(selected_indices, :);
 Y_selected = Y(selected_indices);
 Mdl = fitcsvm (X_selected, Y_selected, 'ClassNames', selected_classes);
 CMdl = crossval (Mdl)
CMdl =

  ClassificationPartitionedModel

      CrossValidatedModel: 'SVM'
             ResponseName: 'Y'
               ClassNames: {'setosa' 'versicolor'}
          NumObservations: 100
                    KFold: 10
           ScoreTransform: 'none'

A structure with fields Function and Scale, and Order for a polynomial kernel. Function names the kernel as MATLAB names it, so a radial basis kernel reports 'gaussian' whichever spelling was given. This property is read-only.

Create a support vectors machine classifier and its compact version

 rng (42);

and compare their size

 load fisheriris
 X = meas;
 Y = species;
 selected_classes = unique (Y)(randperm (3, 2));
 selected_indices = ismember (Y, selected_classes);
 X_selected = X(selected_indices, :);
 Y_selected = Y(selected_indices);
 Mdl = fitcsvm (X_selected, Y_selected, 'ClassNames', selected_classes);
 CMdl = crossval (Mdl)
CMdl =

  ClassificationPartitionedModel

      CrossValidatedModel: 'SVM'
             ResponseName: 'Y'
               ClassNames: {'setosa' 'versicolor'}
          NumObservations: 100
                    KFold: 10
           ScoreTransform: 'none'

A numeric vector of column indices into X naming the predictors treated as categorical, and empty when none is. This property is read-only.

Create a support vectors machine classifier and its compact version

 rng (42);

and compare their size

 load fisheriris
 X = meas;
 Y = species;
 selected_classes = unique (Y)(randperm (3, 2));
 selected_indices = ismember (Y, selected_classes);
 X_selected = X(selected_indices, :);
 Y_selected = Y(selected_indices);
 Mdl = fitcsvm (X_selected, Y_selected, 'ClassNames', selected_classes);
 CMdl = crossval (Mdl)
CMdl =

  ClassificationPartitionedModel

      CrossValidatedModel: 'SVM'
             ResponseName: 'Y'
               ClassNames: {'setosa' 'versicolor'}
          NumObservations: 100
                    KFold: 10
           ScoreTransform: 'none'

A cell array of character vectors. It matches PredictorNames unless a categorical predictor was expanded into indicator variables. This property is read-only.

Create a support vectors machine classifier and its compact version

 rng (42);

and compare their size

 load fisheriris
 X = meas;
 Y = species;
 selected_classes = unique (Y)(randperm (3, 2));
 selected_indices = ismember (Y, selected_classes);
 X_selected = X(selected_indices, :);
 Y_selected = Y(selected_indices);
 Mdl = fitcsvm (X_selected, Y_selected, 'ClassNames', selected_classes);
 CMdl = crossval (Mdl)
CMdl =

  ClassificationPartitionedModel

      CrossValidatedModel: 'SVM'
             ResponseName: 'Y'
               ClassNames: {'setosa' 'versicolor'}
          NumObservations: 100
                    KFold: 10
           ScoreTransform: 'none'

A character vector specifying the name of the response variable Y. This property is read-only.

Create a support vectors machine classifier and its compact version

 rng (42);

and compare their size

 load fisheriris
 X = meas;
 Y = species;
 selected_classes = unique (Y)(randperm (3, 2));
 selected_indices = ismember (Y, selected_classes);
 X_selected = X(selected_indices, :);
 Y_selected = Y(selected_indices);
 Mdl = fitcsvm (X_selected, Y_selected, 'ClassNames', selected_classes);
 CMdl = crossval (Mdl)
CMdl =

  ClassificationPartitionedModel

      CrossValidatedModel: 'SVM'
             ResponseName: 'Y'
               ClassNames: {'setosa' 'versicolor'}
          NumObservations: 100
                    KFold: 10
           ScoreTransform: 'none'

An array of unique values of the response variable Y, which has the same data types as the data in Y. This property is read-only. ClassNames can have any of the following datatypes:

  • Cell array of character vectors
  • Character array
  • Logical vector
  • Numeric vector

Create a support vectors machine classifier and its compact version

 rng (42);

and compare their size

 load fisheriris
 X = meas;
 Y = species;
 selected_classes = unique (Y)(randperm (3, 2));
 selected_indices = ismember (Y, selected_classes);
 X_selected = X(selected_indices, :);
 Y_selected = Y(selected_indices);
 Mdl = fitcsvm (X_selected, Y_selected, 'ClassNames', selected_classes);
 CMdl = crossval (Mdl)
CMdl =

  ClassificationPartitionedModel

      CrossValidatedModel: 'SVM'
             ResponseName: 'Y'
               ClassNames: {'setosa' 'versicolor'}
          NumObservations: 100
                    KFold: 10
           ScoreTransform: 'none'

A numeric row vector with one entry per class, in the order of ClassNames, summing to one. This property is read-only.

Create a support vectors machine classifier and its compact version

 rng (42);

and compare their size

 load fisheriris
 X = meas;
 Y = species;
 selected_classes = unique (Y)(randperm (3, 2));
 selected_indices = ismember (Y, selected_classes);
 X_selected = X(selected_indices, :);
 Y_selected = Y(selected_indices);
 Mdl = fitcsvm (X_selected, Y_selected, 'ClassNames', selected_classes);
 CMdl = crossval (Mdl)
CMdl =

  ClassificationPartitionedModel

      CrossValidatedModel: 'SVM'
             ResponseName: 'Y'
               ClassNames: {'setosa' 'versicolor'}
          NumObservations: 100
                    KFold: 10
           ScoreTransform: 'none'

A numeric square matrix, where Cost(i,j) is the cost of classifying an observation of class i as class j. This property is read-only.

Create a support vectors machine classifier and its compact version

 rng (42);

and compare their size

 load fisheriris
 X = meas;
 Y = species;
 selected_classes = unique (Y)(randperm (3, 2));
 selected_indices = ismember (Y, selected_classes);
 X_selected = X(selected_indices, :);
 Y_selected = Y(selected_indices);
 Mdl = fitcsvm (X_selected, Y_selected, 'ClassNames', selected_classes);
 CMdl = crossval (Mdl)
CMdl =

  ClassificationPartitionedModel

      CrossValidatedModel: 'SVM'
             ResponseName: 'Y'
               ClassNames: {'setosa' 'versicolor'}
          NumObservations: 100
                    KFold: 10
           ScoreTransform: 'none'

A numeric vector of the same length as the columns in X containing the standard deviations of predictor variables. If the predictor variables have not been standardized, then Sigma is empty. This property is read-only.

Create a support vectors machine classifier and its compact version

 rng (42);

and compare their size

 load fisheriris
 X = meas;
 Y = species;
 selected_classes = unique (Y)(randperm (3, 2));
 selected_indices = ismember (Y, selected_classes);
 X_selected = X(selected_indices, :);
 Y_selected = Y(selected_indices);
 Mdl = fitcsvm (X_selected, Y_selected, 'ClassNames', selected_classes);
 CMdl = crossval (Mdl)
CMdl =

  ClassificationPartitionedModel

      CrossValidatedModel: 'SVM'
             ResponseName: 'Y'
               ClassNames: {'setosa' 'versicolor'}
          NumObservations: 100
                    KFold: 10
           ScoreTransform: 'none'

A numeric vector of the same length as the columns in X containing the means of predictor variables. If the predictor variables have not been standardized, then Mu is empty. This property is read-only.

Create a support vectors machine classifier and its compact version

 rng (42);

and compare their size

 load fisheriris
 X = meas;
 Y = species;
 selected_classes = unique (Y)(randperm (3, 2));
 selected_indices = ismember (Y, selected_classes);
 X_selected = X(selected_indices, :);
 Y_selected = Y(selected_indices);
 Mdl = fitcsvm (X_selected, Y_selected, 'ClassNames', selected_classes);
 CMdl = crossval (Mdl)
CMdl =

  ClassificationPartitionedModel

      CrossValidatedModel: 'SVM'
             ResponseName: 'Y'
               ClassNames: {'setosa' 'versicolor'}
          NumObservations: 100
                    KFold: 10
           ScoreTransform: 'none'

The coefficients of the trained SVM classifier specified as an s×1 numeric vector, where s is the number of support vectors, rows (obj.SupportVectors). If the SVM classifier was trained with a kernel function other than 'linear', then Alpha is empty. This property is read-only.

Create a support vectors machine classifier and its compact version

 rng (42);

and compare their size

 load fisheriris
 X = meas;
 Y = species;
 selected_classes = unique (Y)(randperm (3, 2));
 selected_indices = ismember (Y, selected_classes);
 X_selected = X(selected_indices, :);
 Y_selected = Y(selected_indices);
 Mdl = fitcsvm (X_selected, Y_selected, 'ClassNames', selected_classes);
 CMdl = crossval (Mdl)
CMdl =

  ClassificationPartitionedModel

      CrossValidatedModel: 'SVM'
             ResponseName: 'Y'
               ClassNames: {'setosa' 'versicolor'}
          NumObservations: 100
                    KFold: 10
           ScoreTransform: 'none'

The linear predictor coefficients specified as an s×1 numeric vector, where s is the number of support vectors, rows (obj.SupportVectors). If the SVM classifier was trained with a 'linear' kernel function, then Beta is empty. This property is read-only.

Create a support vectors machine classifier and its compact version

 rng (42);

and compare their size

 load fisheriris
 X = meas;
 Y = species;
 selected_classes = unique (Y)(randperm (3, 2));
 selected_indices = ismember (Y, selected_classes);
 X_selected = X(selected_indices, :);
 Y_selected = Y(selected_indices);
 Mdl = fitcsvm (X_selected, Y_selected, 'ClassNames', selected_classes);
 CMdl = crossval (Mdl)
CMdl =

  ClassificationPartitionedModel

      CrossValidatedModel: 'SVM'
             ResponseName: 'Y'
               ClassNames: {'setosa' 'versicolor'}
          NumObservations: 100
                    KFold: 10
           ScoreTransform: 'none'

The bias term specified as a scalar. This property is read-only.

Create a support vectors machine classifier and its compact version

 rng (42);

and compare their size

 load fisheriris
 X = meas;
 Y = species;
 selected_classes = unique (Y)(randperm (3, 2));
 selected_indices = ismember (Y, selected_classes);
 X_selected = X(selected_indices, :);
 Y_selected = Y(selected_indices);
 Mdl = fitcsvm (X_selected, Y_selected, 'ClassNames', selected_classes);
 CMdl = crossval (Mdl)
CMdl =

  ClassificationPartitionedModel

      CrossValidatedModel: 'SVM'
             ResponseName: 'Y'
               ClassNames: {'setosa' 'versicolor'}
          NumObservations: 100
                    KFold: 10
           ScoreTransform: 'none'

The support vector class labels specified as an s×1 numeric vector, where s is the number of support vectors, rows (obj.SupportVectors). A value of +1 in SupportVectorLabels indicates that the corresponding support vector belongs to the positive class (ClassNames{2}). A value of -1 indicates that the corresponding support vector belongs to the negative class (ClassNames{1}). This property is read-only.

Create a support vectors machine classifier and its compact version

 rng (42);

and compare their size

 load fisheriris
 X = meas;
 Y = species;
 selected_classes = unique (Y)(randperm (3, 2));
 selected_indices = ismember (Y, selected_classes);
 X_selected = X(selected_indices, :);
 Y_selected = Y(selected_indices);
 Mdl = fitcsvm (X_selected, Y_selected, 'ClassNames', selected_classes);
 CMdl = crossval (Mdl)
CMdl =

  ClassificationPartitionedModel

      CrossValidatedModel: 'SVM'
             ResponseName: 'Y'
               ClassNames: {'setosa' 'versicolor'}
          NumObservations: 100
                    KFold: 10
           ScoreTransform: 'none'

The support vectors of the trained SVM classifier specified an s×p numeric matrix, where s is the number of support vectors, rows (obj.SupportVectors), and p is the number of predictor variables in the predictor data. This property is read-only.

Create a support vectors machine classifier and its compact version

 rng (42);

and compare their size

 load fisheriris
 X = meas;
 Y = species;
 selected_classes = unique (Y)(randperm (3, 2));
 selected_indices = ismember (Y, selected_classes);
 X_selected = X(selected_indices, :);
 Y_selected = Y(selected_indices);
 Mdl = fitcsvm (X_selected, Y_selected, 'ClassNames', selected_classes);
 CMdl = crossval (Mdl)
CMdl =

  ClassificationPartitionedModel

      CrossValidatedModel: 'SVM'
             ResponseName: 'Y'
               ClassNames: {'setosa' 'versicolor'}
          NumObservations: 100
                    KFold: 10
           ScoreTransform: 'none'

Specified as a function handle for transforming the classification scores. Add or change the ScoreTransform property using dot notation as in:

  • obj.ScoreTransform = 'function_name'
  • obj.ScoreTransform = @function_handle

When specified as a character vector, it can be any of the following built-in functions. Nevertheless, the ScoreTransform property always stores their function handle equivalent.

ValueDescription
'doublelogit'1 ./ (1 + exp (-2 × x))
'invlogit'log (x ./ (1 - x))
'ismax'Sets the score for the class with the largest score to 1, and for all other classes to 0
'logit'1 ./ (1 + exp (-x))
'none'x (no transformation)
'identity'x (no transformation)
'sign' -1 for x < 0, 0 for x = 0, 1 for x > 0
'symmetric'2 × x - 1
'symmetricismax'Sets the score for the class with the largest score to 1, and for all other classes to -1
'symmetriclogit'2 ./ (1 + exp (-x)) - 1

Create a support vectors machine classifier and its compact version

 rng (42);

and compare their size

 load fisheriris
 X = meas;
 Y = species;
 selected_classes = unique (Y)(randperm (3, 2));
 selected_indices = ismember (Y, selected_classes);
 X_selected = X(selected_indices, :);
 Y_selected = Y(selected_indices);
 Mdl = fitcsvm (X_selected, Y_selected, 'ClassNames', selected_classes);
 CMdl = crossval (Mdl)
CMdl =

  ClassificationPartitionedModel

      CrossValidatedModel: 'SVM'
             ResponseName: 'Y'
               ClassNames: {'setosa' 'versicolor'}
          NumObservations: 100
                    KFold: 10
           ScoreTransform: 'none'

The CompactClassificationSVM class offers the following public methods:

CompactClassificationSVM: obj = CompactClassificationSVM (Mdl)
CompactClassificationSVM: obj = CompactClassificationSVM ()

Mdl is the ClassificationSVM object to compact. The documented way to reach this constructor is the compact method.

Called with no arguments it returns an object with its properties empty, which is how a saved model is rebuilt before its values are filled in.

Create a support vectors machine classifier and its compact version

 rng (42);

and compare their size

 load fisheriris
 X = meas;
 Y = species;
 selected_classes = unique (Y)(randperm (3, 2));
 selected_indices = ismember (Y, selected_classes);
 X_selected = X(selected_indices, :);
 Y_selected = Y(selected_indices);
 Mdl = fitcsvm (X_selected, Y_selected, 'ClassNames', selected_classes);
 CMdl = crossval (Mdl)
CMdl =

  ClassificationPartitionedModel

      CrossValidatedModel: 'SVM'
             ResponseName: 'Y'
               ClassNames: {'setosa' 'versicolor'}
          NumObservations: 100
                    KFold: 10
           ScoreTransform: 'none'
CompactClassificationSVM: obj = discardSupportVectors (obj)

obj = discardSupportVectors (obj) empties Alpha, SupportVectors and SupportVectorLabels, leaving Beta and Bias to decide every prediction. A linear kernel needs nothing else, so the returned model predicts what it predicted before while carrying one vector in place of many.

The kernel must be linear. Under any other the support vectors are part of the decision function and cannot be dropped. Discarding twice is not an error and changes nothing.

See also: fitcsvm, ClassificationSVM, CompactClassificationSVM

Create a support vectors machine classifier and its compact version

 rng (42);

and compare their size

 load fisheriris
 X = meas;
 Y = species;
 selected_classes = unique (Y)(randperm (3, 2));
 selected_indices = ismember (Y, selected_classes);
 X_selected = X(selected_indices, :);
 Y_selected = Y(selected_indices);
 Mdl = fitcsvm (X_selected, Y_selected, 'ClassNames', selected_classes);
 CMdl = crossval (Mdl)
CMdl =

  ClassificationPartitionedModel

      CrossValidatedModel: 'SVM'
             ResponseName: 'Y'
               ClassNames: {'setosa' 'versicolor'}
          NumObservations: 100
                    KFold: 10
           ScoreTransform: 'none'
CompactClassificationSVM: label = predict (obj, XC)
CompactClassificationSVM: [label, score] = predict (obj, XC)
CompactClassificationSVM: [label, score, cost] = predict (obj, XC)

label = predict (obj, XC) returns the vector of labels predicted for the corresponding instances in XC, using the predictor data in the CompactClassificationSVM model, obj. For one-class SVM model, +1 or -1 is returned.

  • obj must be a CompactClassificationSVM class object.
  • XC must be an M×P numeric matrix with the same number of features P as the corresponding predictors of the SVM model in obj.

[label, score] = predict (obj, XC) also returns score, which contains the decision values for each prediction. A ScoreTransform assigned to obj is applied to them, so score holds whatever that transform returns. Posterior probabilities need a transform fitted to the model, which this package does not compute yet.

Deviation from MATLAB. cost is the expected cost of each assignment, sum_j P(j) Cost(j,k). An SVM score is a signed distance to the boundary and not a posterior, so the only distribution available is the one concentrated on the predicted class and cost is the row of Cost belonging to it. MATLAB returns the column instead, which is the same matrix read the wrong way and contradicts its own ClassificationKNN, ClassificationDiscriminant and ClassificationNaiveBayes on any asymmetric cost matrix; the two agree wherever Cost is symmetric, the default included. Measured on R2024a.

See also: CompactClassificationSVM, ClassificationSVM

Create a support vectors machine classifier and its compact version

 rng (42);

and compare their size

 load fisheriris
 X = meas;
 Y = species;
 selected_classes = unique (Y)(randperm (3, 2));
 selected_indices = ismember (Y, selected_classes);
 X_selected = X(selected_indices, :);
 Y_selected = Y(selected_indices);
 Mdl = fitcsvm (X_selected, Y_selected, 'ClassNames', selected_classes);
 CMdl = crossval (Mdl)
CMdl =

  ClassificationPartitionedModel

      CrossValidatedModel: 'SVM'
             ResponseName: 'Y'
               ClassNames: {'setosa' 'versicolor'}
          NumObservations: 100
                    KFold: 10
           ScoreTransform: 'none'
CompactClassificationSVM: m = margin (obj, X, Y)

m = margin (obj, X, Y) returns the classification margins for obj with data X and classification Y. m is a numeric vector of length size (X,1).

  • obj is a CompactClassificationSVM object.
  • X must be a N×P numeric matrix of input data where rows correspond to observations and columns correspond to features or variables.
  • Y is N×1 matrix or cell matrix containing the class labels of corresponding predictor data in X. Y must have same numbers of Rows as X.

The classification margin for each observation is the difference between the classification score for the true class and the maximal classification score for the false classes.

See also: CompactClassificationSVM

Create a support vectors machine classifier and its compact version

 rng (42);

and compare their size

 load fisheriris
 X = meas;
 Y = species;
 selected_classes = unique (Y)(randperm (3, 2));
 selected_indices = ismember (Y, selected_classes);
 X_selected = X(selected_indices, :);
 Y_selected = Y(selected_indices);
 Mdl = fitcsvm (X_selected, Y_selected, 'ClassNames', selected_classes);
 CMdl = crossval (Mdl)
CMdl =

  ClassificationPartitionedModel

      CrossValidatedModel: 'SVM'
             ResponseName: 'Y'
               ClassNames: {'setosa' 'versicolor'}
          NumObservations: 100
                    KFold: 10
           ScoreTransform: 'none'
CompactClassificationSVM: L = loss (obj, X, Y)
CompactClassificationSVM: L = loss (…, name, value)

L = loss (obj, X, Y) computes the loss, L, using the default loss function 'classiferror'.

  • obj is a CompactClassificationSVM object.
  • X must be a N×P numeric matrix of input data where rows correspond to observations and columns correspond to features or variables.
  • Y is N×1 matrix or cell matrix containing the class labels of corresponding predictor data in X. Y must have same numbers of Rows as X.

L = loss (…, name, value) allows additional options specified by name-value pairs:

NameValue
'LossFun'Specifies the loss function to use. Can be a function handle with four input arguments (C, S, W, Cost) which returns a scalar value or one of: ’binodeviance’, ’classifcost’, ’classiferror’, ’exponential’, ’hinge’, ’logit’,’mincost’, ’quadratic’.
  • C is a logical matrix of size N×K, where N is the number of observations and K is the number of classes. The element C(i,j) is true if the class label of the i-th observation is equal to the j-th class.
  • S is a numeric matrix of size N×K, where each element represents the classification score for the corresponding class.
  • W is a numeric vector of length N, representing the observation weights.
  • Cost is a K×K matrix representing the misclassification costs.
'Weights'Specifies observation weights, must be a numeric vector of length equal to the number of rows in X. Default is ones (size (X, 1)). loss normalizes the weights so that observation weights in each class sum to the prior probability of that class. When you supply Weights, loss computes the weighted classification loss.

See also: CompactClassificationSVM

Create a support vectors machine classifier and its compact version

 rng (42);

and compare their size

 load fisheriris
 X = meas;
 Y = species;
 selected_classes = unique (Y)(randperm (3, 2));
 selected_indices = ismember (Y, selected_classes);
 X_selected = X(selected_indices, :);
 Y_selected = Y(selected_indices);
 Mdl = fitcsvm (X_selected, Y_selected, 'ClassNames', selected_classes);
 CMdl = crossval (Mdl)
CMdl =

  ClassificationPartitionedModel

      CrossValidatedModel: 'SVM'
             ResponseName: 'Y'
               ClassNames: {'setosa' 'versicolor'}
          NumObservations: 100
                    KFold: 10
           ScoreTransform: 'none'
CompactClassificationSVM: e = edge (obj, X, Y)
CompactClassificationSVM: e = edge (…, "Weights", w)

e = edge (obj, X, Y) reduces the vector that margin returns to a single number, the mean margin over the rows of X. It says how far the model puts the true class ahead of its nearest rival on average, so a larger edge is a better model, and unlike a loss it is not bounded above and rewards confidence rather than bare correctness.

e = edge (…, "Weights", w) takes the weighted mean instead, with one weight per row of X.

Create a support vectors machine classifier and its compact version

 rng (42);

and compare their size

 load fisheriris
 X = meas;
 Y = species;
 selected_classes = unique (Y)(randperm (3, 2));
 selected_indices = ismember (Y, selected_classes);
 X_selected = X(selected_indices, :);
 Y_selected = Y(selected_indices);
 Mdl = fitcsvm (X_selected, Y_selected, 'ClassNames', selected_classes);
 CMdl = crossval (Mdl)
CMdl =

  ClassificationPartitionedModel

      CrossValidatedModel: 'SVM'
             ResponseName: 'Y'
               ClassNames: {'setosa' 'versicolor'}
          NumObservations: 100
                    KFold: 10
           ScoreTransform: 'none'
CompactClassificationSVM: savemodel (obj, filename)

savemodel (obj, filename) saves each property of a CompactClassificationSVM object into an Octave binary file, the name of which is specified in filename, along with an extra variable, which defines the type classification object these variables constitute. Use loadmodel in order to load a classification object into Octave’s workspace.

See also: loadmodel, ClassificationSVM, CompactClassificationSVM

Create a support vectors machine classifier and its compact version

 rng (42);

and compare their size

 load fisheriris
 X = meas;
 Y = species;
 selected_classes = unique (Y)(randperm (3, 2));
 selected_indices = ismember (Y, selected_classes);
 X_selected = X(selected_indices, :);
 Y_selected = Y(selected_indices);
 Mdl = fitcsvm (X_selected, Y_selected, 'ClassNames', selected_classes);
 CMdl = crossval (Mdl)
CMdl =

  ClassificationPartitionedModel

      CrossValidatedModel: 'SVM'
             ResponseName: 'Y'
               ClassNames: {'setosa' 'versicolor'}
          NumObservations: 100
                    KFold: 10
           ScoreTransform: 'none'

Examples

 rng (42);

and compare their size

 load fisheriris
 X = meas;
 Y = species;
 selected_classes = unique (Y)(randperm (3, 2));
 selected_indices = ismember (Y, selected_classes);
 X_selected = X(selected_indices, :);
 Y_selected = Y(selected_indices);
 Mdl = fitcsvm (X_selected, Y_selected, 'ClassNames', selected_classes);
 CMdl = crossval (Mdl)
CMdl =

  ClassificationPartitionedModel

      CrossValidatedModel: 'SVM'
             ResponseName: 'Y'
               ClassNames: {'setosa' 'versicolor'}
          NumObservations: 100
                    KFold: 10
           ScoreTransform: 'none'