compact

Reduce size of support vector machine (SVM) classifier

Description

example

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

CompactSVMModel does not contain the training data, whereas SVMModel contains the training data in its X and Y properties. Therefore, although you can predict class labels using CompactSVMModel, you cannot perform tasks such as cross-validation with the compact SVM classifier.

Examples

collapse all

Reduce the size of a full SVM classifier by removing the training data. Full SVM classifiers (that is, ClassificationSVM classifiers) hold the training data. To improve efficiency, use a smaller classifier.

Load the ionosphere data set.

load ionosphere

Train an SVM classifier. Standardize the predictor data and specify the order of the classes.

SVMModel = fitcsvm(X,Y,'Standardize',true,...
    'ClassNames',{'b','g'})
SVMModel = 
  ClassificationSVM
             ResponseName: 'Y'
    CategoricalPredictors: []
               ClassNames: {'b'  'g'}
           ScoreTransform: 'none'
          NumObservations: 351
                    Alpha: [90x1 double]
                     Bias: -0.1342
         KernelParameters: [1x1 struct]
                       Mu: [1x34 double]
                    Sigma: [1x34 double]
           BoxConstraints: [351x1 double]
          ConvergenceInfo: [1x1 struct]
          IsSupportVector: [351x1 logical]
                   Solver: 'SMO'


  Properties, Methods

SVMModel is a ClassificationSVM classifier.

Reduce the size of the SVM classifier.

CompactSVMModel = compact(SVMModel)
CompactSVMModel = 
  classreg.learning.classif.CompactClassificationSVM
             ResponseName: 'Y'
    CategoricalPredictors: []
               ClassNames: {'b'  'g'}
           ScoreTransform: 'none'
                    Alpha: [90x1 double]
                     Bias: -0.1342
         KernelParameters: [1x1 struct]
                       Mu: [1x34 double]
                    Sigma: [1x34 double]
           SupportVectors: [90x34 double]
      SupportVectorLabels: [90x1 double]


  Properties, Methods

CompactSVMModel is a CompactClassificationSVM classifier.

Display the amount of memory each classifier uses.

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

  CompactSVMModel      1x1              31074  classreg.learning.classif.CompactClassificationSVM              
  SVMModel             1x1             141404  ClassificationSVM                                               

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

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

To further reduce the size of your compact SVM classifier, use the discardSupportVectors function to discard support vectors.

Input Arguments

collapse all

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

Introduced in R2014a