Main Content


Compact regression ensemble


Compact version of a regression ensemble. The compact version does not include the data for training the regression ensemble. Therefore, you cannot perform some tasks with a compact regression ensemble, such as cross validation. Use a compact regression ensemble for making predictions (regressions) of new data.




ens = compact(fullEns) constructs a compact decision ensemble from a full decision ensemble.

Input Arguments

expand all

Regression ensemble object, specified as the output of fitrensemble.


expand all

This property is read-only.

Categorical predictor indices, specified as a vector of positive integers. CategoricalPredictors contains index values indicating that the corresponding predictors are categorical. The index values are between 1 and p, where p is the number of predictors used to train the model. If none of the predictors are categorical, then this property is empty ([]).

Data Types: single | double

This property is read-only.

How the ensemble combines weak learner weights, returned as either 'WeightedAverage' or 'WeightedSum'.

Data Types: char

This property is read-only.

Expanded predictor names, returned as a cell array of character vectors.

If the model uses encoding for categorical variables, then ExpandedPredictorNames includes the names that describe the expanded variables. Otherwise, ExpandedPredictorNames is the same as PredictorNames.

Data Types: cell

This property is read-only.

Number of trained weak learners in the ensemble, returned as a positive integer.

Data Types: double

This property is read-only.

Predictor names, specified as a cell array of character vectors. The order of the entries in PredictorNames is the same as in the training data.

Data Types: cell

This property is read-only.

Name of the response variable, returned as a character vector.

Data Types: char

Function for transforming raw response values, specified as a function handle or function name. The default is 'none', which means @(y)y, or no transformation. The function should accept a vector (the original response values) and return a vector of the same size (the transformed response values).

Example: Suppose you create a function handle that applies an exponential transformation to an input vector by using myfunction = @(y)exp(y). Then, you can specify the response transformation as 'ResponseTransform',myfunction.

Data Types: char | string | function_handle

Trained regression models, returned as a cell vector. The entries of the cell vector contain the corresponding compact regression models.

If Method is 'LogitBoost' or 'GentleBoost', then the ensemble stores trained learner j in the CompactRegressionLearner property of the object stored in Trained{j}. That is, to access trained learner j, use ens.Trained{j}.CompactRegressionLearner.

Data Types: cell

This property is read-only.

Trained weights for the weak learners in the ensemble, returned as a numeric vector. TrainedWeights has T elements, where T is the number of weak learners in learners. The ensemble computes predicted response by aggregating weighted predictions from its learners.

Data Types: double

Object Functions

gatherGather properties of Statistics and Machine Learning Toolbox object from GPU
limeLocal interpretable model-agnostic explanations (LIME)
lossRegression error for regression ensemble model
partialDependenceCompute partial dependence
plotPartialDependenceCreate partial dependence plot (PDP) and individual conditional expectation (ICE) plots
predictPredict responses using regression ensemble model
predictorImportanceEstimates of predictor importance for regression ensemble of decision trees
removeLearnersRemove members of compact regression ensemble
shapleyShapley values


collapse all

Create a compact regression ensemble for efficiently making predictions on new data.

Load the carsmall data set. Consider a model that explains a car's fuel economy (MPG) using its weight (Weight) and number of cylinders (Cylinders).

load carsmall
X = [Weight Cylinders];
Y = MPG;

Train a boosted ensemble of 100 regression trees using the LSBoost. Specify that Cylinders is a categorical variable.

Mdl = fitrensemble(X,Y,'PredictorNames',{'W','C'},...
Mdl = 
           PredictorNames: {'W'  'C'}
             ResponseName: 'Y'
    CategoricalPredictors: 2
        ResponseTransform: 'none'
          NumObservations: 94
               NumTrained: 100
                   Method: 'LSBoost'
             LearnerNames: {'Tree'}
     ReasonForTermination: 'Terminated normally after completing the requested number of training cycles.'
                  FitInfo: [100x1 double]
       FitInfoDescription: {2x1 cell}
           Regularization: []

Mdl is a RegressionEnsemble model object that contains the training data, among other things.

Create a compact version of Mdl.

CMdl = compact(Mdl)
CMdl = 
           PredictorNames: {'W'  'C'}
             ResponseName: 'Y'
    CategoricalPredictors: 2
        ResponseTransform: 'none'
               NumTrained: 100

CMdl is a CompactRegressionEnsemble model object. CMdl is almost the same as Mdl. One exception is that CMdl does not store the training data.

Compare the amounts of space consumed by Mdl and CMdl.

mdlInfo = whos('Mdl');
cMdlInfo = whos('CMdl');
[mdlInfo.bytes cMdlInfo.bytes]
ans = 1×2

      532067      506417

Mdl consumes more space than CMdl.

CMdl.Trained stores the trained regression trees (CompactRegressionTree model objects) that compose Mdl.

Display a graph of the first tree in the compact ensemble.


By default, fitrensemble grows shallow trees for boosted ensembles of trees.

Predict the fuel economy of a typical car using the compact ensemble.

typicalX = [mean(X(:,1)) mode(X(:,2))];
predMeanX = predict(CMdl,typicalX)
predMeanX = 26.2520


For a compact ensemble of regression trees, the Trained property of ens stores a cell vector of ens.NumTrained CompactRegressionTree model objects. For a textual or graphical display of tree t in the cell vector, enter


Extended Capabilities

Version History

Introduced in R2011a