Main Content


Reduce size of classification ensemble model



cens = compact(ens) returns a CompactClassificationEnsemble version of the trained classification ensemble model ens.

You can predict classifications using the CompactClassificationEnsemble model object cens in the same way as when you use ens. However, because cens does not contain training data, you cannot perform certain tasks, such as cross-validation.


collapse all

Compare the size of a classification ensemble for the Fisher iris data to the compact version of the ensemble.

Load the Fisher iris data set.

load fisheriris

Train an ensemble of 100 boosted classification trees using AdaBoostM2.

t = templateTree(MaxNumSplits=1); % Weak learner template tree object
ens = fitcensemble(meas,species,"Method","AdaBoostM2","Learners",t);

Create a compact version of ens and compare ensemble sizes.

cens = compact(ens);
b = whos("ens");  % b.bytes = size of ens
c = whos("cens"); % c.bytes = size of cens
[b.bytes c.bytes] % Shows cens uses less memory
ans = 1×2

      464631      423531

The compact version of the ensemble uses less memory than the full ensemble. Note that the ensemble sizes can vary slightly, depending on your operating system.

Input Arguments

collapse all

Full classification ensemble model, specified as a ClassificationEnsemble model object trained with fitcensemble.

Extended Capabilities

Version History

Introduced in R2011a