This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.


Compact classification ensemble


cens = compact(ens)


cens = compact(ens) creates a compact version of ens. You can predict classifications using cens exactly as you can using ens. However, since cens does not contain training data, you cannot perform some actions, such as cross validation.

Input Arguments


A classification ensemble created with fitcensemble.

Output Arguments


A compact classification ensemble. cens has class CompactClassificationEnsemble.


expand 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

      428573      388174

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.