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

    %% Prune Regression Tree
%%
% Load the |carsmall| data set. Consider |Horsepower| and |Weight| as
% predictor variables.
load carsmall;
X = [Weight Horsepower];
varNames = {'Weight' 'Horsepower'};
%%
% Grow a regression tree using the entire data set. View the tree.
Mdl = fitrtree(X,MPG,'PredictorNames',varNames)
view(Mdl,'Mode','graph');
%%
% The regression tree has 16 pruning levels.
%%
% Prune the regression tree to pruning-level 10.  View the pruned tree.
MdlPruned = prune(Mdl,'Level',10);
view(MdlPruned,'Mode','graph');
%%
% The pruned tree has six pruning levels.  
%%
% Alternatively, you can use the pruning-level field in the Regression tree
% viewer to prune the tree.