www.gusucode.com > stats 源码程序 matlab案例代码 > stats/FindEnsembleSizeUsingOOBQuantileRegressionErrorExample.m
%% Find Appropriate Ensemble Size Using Out-of-Bag Quantile Regression Error %% % Load the |carsmall| data set. Consider a model that predicts the fuel % economy of a car given its engine displacement, weight, and number of % cylinders. load carsmall X = table(Displacement,Weight,Cylinders,MPG); %% % Train an ensemble of bagged regression trees using the entire data set. % Specify 250 weak learners and save the out-of-bag indices. rng('default'); % For reproducibility Mdl = TreeBagger(250,X,'MPG','Method','regression',... 'OOBPrediction','on'); %% % Estimate the cumulative; out-of-bag; 0.25, 0.5, and 0.75 % quantile regression errors. err = oobQuantileError(Mdl,'Quantile',[0.25 0.5 0.75],'Mode','cumulative'); %% % |err| is an 250-by-3 matrix of cumulative, out-of-bag, quantile % regression errors. Columns correspond to quantile probabilities and rows % correspond to trees in the ensemble. The errors are cumulative, so they % incorporate aggregated predictions from previous trees. %% % Plot the cumulative, out-of-bag, quantile errors on the same plot. figure; plot(err); legend('0.25 quantile error','0.5 quantile error','0.75 quantile error'); ylabel('Out-of-bag quantile error'); xlabel('Tree index'); title('Cumulative, Out-of-Bag, Quantile Regression Error') %% % All quantile error curves appear to level off after training about 50 % trees. So, training 50 trees appears to be sufficient to achieve minimal % quantile error for the three quantile probabilities.