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

    %% Reduce Size of Classification Ensemble
% Create a compact classification ensemble for efficiently making
% predictions on new data.
%%
% Load the |ionosphere| data set.
load ionosphere
%%
% Train a boosted ensemble of 100 classification trees using all
% measurements and the |AdaBoostM1| method.
Mdl = fitensemble(X,Y,'AdaBoostM1',100,'tree')
%%
% |Mdl| is a |ClassificationEnsemble| model object that contains the
% training data, among other things.
%%
% Create a compact version of |Mdl|.
CMdl = compact(Mdl)
%%
% |CMdl| is a |CompactClassificationEnsemble| model object.  |CMdl|
% is almost the same as |Mdl|.  One exception is that it does not store the
% training data.
%%
% Compare the amounts of space consumed by |Mdl| and |CMdl|.
mdlInfo = whos('Mdl');
cMdlInfo = whos('CMdl');
[mdlInfo.bytes cMdlInfo.bytes]
%%
% |Mdl| consumes more space than |CMdl|.
%%
% |CMdl.Trained| stores the trained classification trees
% (|CompactClassificationTree| model objects) that compose |Mdl|.
%%
% Display a graph of the first tree in the compact ensemble.
view(CMdl.Trained{1},'Mode','graph');
%%
% By default, |fitensemble| grows stumps for boosted ensembles of trees.
%%
% Predict the label of the mean of |X| using the compact ensemble.
predMeanX = predict(CMdl,mean(X))