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

Class: TreeBagger

Compact ensemble of decision trees

Description

CMdl = compact(Mdl) creates a compact version of Mdl, a TreeBagger model object. You can predict regressions using CMdl exactly as you can using Mdl. However, since CMdl does not contain training data, you cannot perform some actions, such as make out-of-bag predictions using oobPredict.

Input Arguments

Mdl

A regression ensemble created with TreeBagger.

Output Arguments

CMdl

A compact regression ensemble. CMdl is of class CompactTreeBagger.

Examples

expand all

Create a compact bag of trees for efficiently making predictions on new data.

Load the ionosphere data set.

load ionosphere

Train a bag of 100 classification trees using all measurements and the AdaBoostM1 method.

Mdl = TreeBagger(100,X,Y,'Method','classification')
Mdl = 
  TreeBagger
Ensemble with 100 bagged decision trees:
                    Training X:             [351x34]
                    Training Y:              [351x1]
                        Method:       classification
                 NumPredictors:                   34
         NumPredictorsToSample:                    6
                   MinLeafSize:                    1
                 InBagFraction:                    1
         SampleWithReplacement:                    1
          ComputeOOBPrediction:                    0
 ComputeOOBPredictorImportance:                    0
                     Proximity:                   []
                    ClassNames:             'b'             'g'

  Properties, Methods

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

Create a compact version of Mdl.

CMdl = compact(Mdl)
CMdl = 
  CompactTreeBagger
Ensemble with 100 bagged decision trees:
              Method:       classification
       NumPredictors:                   34
          ClassNames: 'b' 'g'

  Properties, Methods

CMdl is a CompactTreeBagger model object. CMdl is almost the same as Mdl. One exception is that it 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

     1066952      925404

Mdl consumes more space than CMdl.

CMdl.Trees stores the trained classification trees (CompactClassificationTree model objects) that compose Mdl.

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

view(CMdl.Trees{1},'Mode','graph');

By default, TreeBagger grows deep trees.

Predict the label of the mean of X using the compact ensemble.

predMeanX = predict(CMdl,mean(X))
predMeanX = 1x1 cell array
    {'g'}