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.


Create compact regression ensemble


cens = compact(ens)


cens = compact(ens) creates a compact version of ens. You can predict regressions 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 regression ensemble created with fitrensemble.

Output Arguments


A compact regression ensemble. cens is of class CompactRegressionEnsemble.


expand all

Compare the size of a regression ensemble for the carsmall data to the size of the compact version of the ensemble.

Load the carsmall data set and select acceleration, number of cylinders, displacement, horsepower, and vehicle weight as predictors.

load carsmall
X = [Acceleration Cylinders Displacement Horsepower Weight];

Train an ensemble of regression trees.

ens = fitrensemble(X,MPG);

Create a compact version of ens and compare ensemble sizes.

cens = compact(ens);
b = whos('ens'); 
c = whos('cens');  
[b.bytes c.bytes]  % b.bytes = size of ens and c.bytes = size of cens
ans = 1×2

      456673      425010

The compact ensemble uses less memory.