compact

Class: ClassificationSVM

Compact support vector machine classifier

Syntax

  • CompactSVMModel = compact(SVMModel) example

Description

example

CompactSVMModel = compact(SVMModel) returns a compact support vector machine (SVM) classifier (CompactSVMModel), the compact version of the trained SVM classifier SVMModel.

CompactSVMModel does not contain the training data, whereas SVMModel contains the training data in its properties SVMModel.X and SVMModel.Y.

Input Arguments

expand all

SVMModel — Full, trained SVM classifierClassificationSVM classifier

Full, trained SVM classifier, specified as a ClassificationSVM model trained using fitcsvm.

Output Arguments

expand all

CompactSVMModel — Compact SVM classifierCompactClassificationSVM classifier

Compact SVM classifier, returned as a CompactClassificationSVM classifier.

Predict class labels using CompactSVMModel exactly as you would using SVMModel. However, since CompactSVMModel does not contain training data, you cannot perform certain tasks, such as cross validation.

Examples

expand all

Reduce the Size of Support Vector Machine Classifiers

Full SVM classifiers (i.e., ClassificationSVM classifiers) hold the training data. For efficiency, you might not want to predict new labels using a large classifier. This example shows how to reduce the size of a full SVM classifier.

Load the ionosphere data set.

load ionosphere

Train an SVM classifier. It is good practice to standardize the predictors and specify the order of the classes.

SVMModel = fitcsvm(X,Y,'Standardize',true,...
    'ClassNames',{'b','g'})
SVMModel = 

  ClassificationSVM
      PredictorNames: {1x34 cell}
        ResponseName: 'Y'
          ClassNames: {'b'  'g'}
      ScoreTransform: 'none'
     NumObservations: 351
               Alpha: [89x1 double]
                Bias: -0.1341
    KernelParameters: [1x1 struct]
                  Mu: [1x34 double]
               Sigma: [1x34 double]
      BoxConstraints: [351x1 double]
     ConvergenceInfo: [1x1 struct]
     IsSupportVector: [351x1 logical]
              Solver: 'SMO'


SVMModel is a ClassificationSVM classifier.

Reduce the size of the SVM classifier.

CompactSVMModel = compact(SVMModel)
CompactSVMModel = 

  classreg.learning.classif.CompactClassificationSVM
         PredictorNames: {1x34 cell}
           ResponseName: 'Y'
             ClassNames: {'b'  'g'}
         ScoreTransform: 'none'
                  Alpha: [89x1 double]
                   Bias: -0.1341
       KernelParameters: [1x1 struct]
                     Mu: [1x34 double]
                  Sigma: [1x34 double]
         SupportVectors: [89x34 double]
    SupportVectorLabels: [89x1 double]


CompactSVMModel is a CompactClassificationSVM classifier.

Display how much memory each classifier uses.

whos('SVMModel','CompactSVMModel')
  Name                 Size             Bytes  Class                                                 Attributes

  CompactSVMModel      1x1              29864  classreg.learning.classif.CompactClassificationSVM              
  SVMModel             1x1             140833  ClassificationSVM                                               

The full SVM classifier (SVMModel) is more than four times the compact SVM classifier (CompactSVMModel).

You can remove SVMModel from the MATLAB® Workspace, and pass CompactSVMModel and new predictor values to predict to efficiently label new observations.

Was this topic helpful?