Documentation

This is machine translation

Translated by Microsoft
Mouse over text to see original. Click the button below to return to the English verison of the page.

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

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

Output Arguments

expand all

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

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
             ResponseName: 'Y'
    CategoricalPredictors: []
               ClassNames: {'b'  'g'}
           ScoreTransform: 'none'
          NumObservations: 351
                    Alpha: [90×1 double]
                     Bias: -0.1343
         KernelParameters: [1×1 struct]
                       Mu: [1×34 double]
                    Sigma: [1×34 double]
           BoxConstraints: [351×1 double]
          ConvergenceInfo: [1×1 struct]
          IsSupportVector: [351×1 logical]
                   Solver: 'SMO'


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: [90×1 double]
                     Bias: -0.1343
         KernelParameters: [1×1 struct]
                       Mu: [1×34 double]
                    Sigma: [1×34 double]
           SupportVectors: [90×34 double]
      SupportVectorLabels: [90×1 double]


CompactSVMModel is a CompactClassificationSVM classifier.

Display how much memory each classifier uses.

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

  CompactSVMModel      1x1              30512  classreg.learning.classif.CompactClassificationSVM              
  SVMModel             1x1             140834  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?