Main Content

compact

Reduce size of multiclass error-correcting output codes (ECOC) model

Description

example

CompactMdl = compact(Mdl) returns a compact multiclass error-correcting output codes (ECOC) model (CompactMdl), the compact version of the trained ECOC model Mdl. CompactMdl is a CompactClassificationECOC object.

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

Examples

collapse all

Reduce the size of a full ECOC model by removing the training data. Full ECOC models (ClassificationECOC models) hold the training data. To improve efficiency, use a smaller classifier.

Load Fisher's iris data set. Specify the predictor data X, the response data Y, and the order of the classes in Y.

load fisheriris
X = meas;
Y = categorical(species);
classOrder = unique(Y);

Train an ECOC model using SVM binary classifiers. Standardize the predictor data using an SVM template t, and specify the order of the classes. During training, the software uses default values for empty options in t.

t = templateSVM('Standardize',true);
Mdl = fitcecoc(X,Y,'Learners',t,'ClassNames',classOrder);

Mdl is a ClassificationECOC model.

Reduce the size of the ECOC model.

CompactMdl = compact(Mdl)
CompactMdl = 
  CompactClassificationECOC
             ResponseName: 'Y'
    CategoricalPredictors: []
               ClassNames: [setosa    versicolor    virginica]
           ScoreTransform: 'none'
           BinaryLearners: {3x1 cell}
             CodingMatrix: [3x3 double]


CompactMdl is a CompactClassificationECOC model. CompactMdl does not store all of the properties that Mdl stores. In particular, it does not store the training data.

Display the amount of memory each classifier uses.

whos('CompactMdl','Mdl')
  Name            Size            Bytes  Class                                                  Attributes

  CompactMdl      1x1             15792  classreg.learning.classif.CompactClassificationECOC              
  Mdl             1x1             29207  ClassificationECOC                                               

The full ECOC model (Mdl) is approximately double the size of the compact ECOC model (CompactMdl).

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

Input Arguments

collapse all

Full, trained multiclass ECOC model, specified as a ClassificationECOC model trained with fitcecoc.

Extended Capabilities

Version History

Introduced in R2014b