Reduce the size of a full ensemble of bagged classification trees by removing the training data and parameters. Then, use the compact ensemble object to make predictions on new data. Using a compact ensemble improves memory efficiency.
Load the ionosphere
data set.
Set the random number generator to default
for reproducibility.
Train an ensemble of 100 bagged classification trees using the entire data set. By default, TreeBagger
grows deep trees.
Mdl
is a TreeBagger
ensemble for classification trees.
Create a compact version of Mdl
.
CMdl =
CompactTreeBagger
Ensemble with 100 bagged decision trees:
Method: classification
NumPredictors: 34
ClassNames: 'b' 'g'
CMdl
is a CompactTreeBagger
ensemble for classification trees.
Display the amount of memory used by each ensemble.
Name Size Bytes Class Attributes
CMdl 1x1 963112 CompactTreeBagger
Mdl 1x1 1107399 TreeBagger
Mdl
takes up more space than CMdl
.
The CMdl.Trees
property is a 100-by-1 cell vector that contains the trained classification trees for the ensemble. Each tree is a CompactClassificationTree
object. View the graphical display of the first trained classification tree.
Predict the label of the mean of X
by using the compact ensemble.
predMeanX = 1x1 cell array
{'g'}