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

    %% Train Boosted Regression Ensemble
%%
% Load the |ionosphere| data set.
load ionosphere
%%
% 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;
%%
% Train a boosted ensemble of 100 regression trees using the |LSBoost|.
% Specify that |Cylinders| is a categorical variable.
Mdl = fitensemble(X,Y,'LSBoost',100,'Tree','PredictorNames',{'W','C'},...
    'CategoricalPredictors',2)
%%
% |Mdl| is a |RegressionEnsemble| model object that contains the
% training data, among other things.
%%
% |Mdl.Trained| is the property that stores a 100-by-1 cell vector
% of the trained regression trees (|CompactRegressionTree| model
% objects) that compose the ensemble.
%%
% Plot a graph of the first trained regression tree.
view(Mdl.Trained{1},'Mode','graph')
%%
% By default, |fitensemble| grows stumps for boosted ensembles of trees.
%%
% Predict the fuel economy of 4,000 pound cars with 4, 6, and 8 cylinders.
XNew = [4000*ones(3,1) [4; 6; 8]];
mpgNew = predict(Mdl,XNew)