www.gusucode.com > stats 源码程序 matlab案例代码 > stats/EstimateTheGeneralizationErrorOfATrainedBoostingEnsembleExample.m
%% Estimate the Generalization Error of a Boosting Ensemble % Estimate the generalization error of a trained, boosting classification % ensemble of decision trees. %% % Load the |ionosphere| data set. % Copyright 2015 The MathWorks, Inc. load ionosphere; %% % Train a decision tree ensemble using AdaBoostM1, 100 learning cycles, and % half of the data chosen randomly. The software validates the algorithm % using the remaining half. rng(2); % For reproducibility ClassTreeEns = fitensemble(X,Y,'AdaBoostM1',100,'Tree',... 'Holdout',0.5); %% % |ClassTreeEns| is a trained |ClassificationEnsemble| ensemble classifier. %% % Determine the cumulative generalization error, i.e., the cumulative % misclassification error of the labels in the validation data). genError = kfoldLoss(ClassTreeEns,'Mode','Cumulative'); %% % |genError| is a 100-by-1 vector, where element _k_ contains the % generalization error after the first _k_ learning cycles. %% % Plot the generalization error over the number of learning cycles. plot(genError); xlabel('Number of Learning Cycles'); ylabel('Generalization Error'); %% % The cumulative generalization error decreases to approximately 7% when 25 % weak learners compose the ensemble classifier.