www.gusucode.com > stats 源码程序 matlab案例代码 > stats/TrainABaggedEnsembleOfClassificationTreesExample.m

    %% Train Bagged Ensemble of Classification Trees
%%
% Load the |ionosphere| data set.
load ionosphere
%%
% Train a bagged ensemble of 100 classification trees using all
% measurements.
rng(1) % For reproducibility
Mdl = fitensemble(X,Y,'bag',100,'Tree','Type','classification')
%%
% |Mdl| is a |ClassificationBaggedEnsemble| model object.
%%
% |Mdl.Trained| is the property that stores a 100-by-1 cell vector
% of the trained classification trees (|CompactClassificationTree| model
% objects) that compose the ensemble.
%%
% Plot a graph of the first trained classification tree.
view(Mdl.Trained{1},'Mode','graph')
%%
% By default, |fitensemble| grows deep decision trees for bagged ensembles.
%%
% Estimate the in-sample misclassification rate.
L = resubLoss(Mdl)
%%
% |L| is 0, which indicates that |Mdl| is perfect at classifying the 
% training data.