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

    %% View Tree from Bag of Trees
%%
% 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;
%%
% Grow a bag of 100 regression trees using all measurements.
rng(1) % For reproducibility
Mdl = TreeBagger(100,X,Y);
%%
% Alternatively, you can use <docid:stats_ug.bu_gvq1 fitensemble> to grow a
% bag of regression trees.
%%
% |Mdl| is a <docid:stats_ug.brz_iy1-1 |TreeBagger|> model object.
% |Mdl.Trees| stores the bag of 100 trained regression trees in a
% 100-by-1 cell array.  That is, each cell in |Mdl.Trees| contains a
% |CompactRegressionTree| model object.
%%
% View a graph of the 10th regression tree in the bag.
Tree10 = Mdl.Trees{10};
view(Tree10,'Mode','graph');
%%
% By default, the software grows deep trees for bags of trees.