Main Content

compact

Class:TreeBagger

Compact ensemble of decision trees

Description

CMdl= compact(Mdl)creates a compact version ofMdl, aTreeBaggermodel object. You can predict regressions usingCMdlexactly as you can usingMdl. However, sinceCMdldoes not contain training data, you cannot perform some actions, such as make out-of-bag predictions usingoobPredict.

Input Arguments

Mdl

A regression ensemble created withTreeBagger.

Output Arguments

CMdl

A compact regression ensemble.CMdlis of classCompactTreeBagger.

Examples

expand all

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

Load theionospheredata set.

loadionosphere

Train a bag of 100 classification trees using all measurements and theAdaBoostM1method.

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

Mdlis aTreeBaggermodel object that contains the training data, among other things.

Create a compact version ofMdl.

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

CMdlis aCompactTreeBaggermodel object.CMdlis almost the same asMdl. One exception is that it does not store the training data.

Compare the amounts of space consumed byMdlandCMdl.

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

Mdlconsumes more space thanCMdl.

CMdl.Treesstores the trained classification trees (CompactClassificationTreemodel objects) that composeMdl.

显示一个图的第一棵树the compact model.

view(CMdl.Trees{1},“模式”,'graph');

Figure Classification tree viewer contains an axes object and other objects of type uimenu, uicontrol. The axes object contains 60 objects of type line, text.

By default,TreeBaggergrows deep trees.

Predict the label of the mean ofXusing the compact ensemble.

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