www.gusucode.com > stats 源码程序 matlab案例代码 > stats/EstimateImportanceOfPredictorsClassExample.m
%% Estimate Importance of Predictors %% % Load the |census1994| data set. Consider a model that predicts a % person's salary category given their age, working class, education level, % martial status, race, sex, capital gain and loss, and number of working hours % per week. load census1994 X = adultdata(:,{'age','workClass','education_num','marital_status','race',... 'sex','capital_gain','capital_loss','hours_per_week','salary'}); rng('default'); % For reproducibility %% % Train a random forest of 50 classification trees using the entire data set. Mdl = fitcensemble(X,'salary','Method','bag','NumLearningCycles',50); %% % |Mdl| is a |ClassificationBaggedEnsemble| model. %% % Estimate predictor importance measures by permuting out-of-bag % observations. Compare the estimates using a bar graph. imp = oobPermutedPredictorImportance(Mdl); figure; bar(imp); title('Out-of-Bag Permuted Predictor Importance Estimates'); ylabel('Estimates'); xlabel('Predictors'); h = gca; h.XTickLabel = Mdl.PredictorNames; h.XTickLabelRotation = 45; h.TickLabelInterpreter = 'none'; %% % |imp| is a 1-by-9 vector of predictor importance estimates. Larger % values indicate predictors that have a greater influence on predictions. % In this case, |marital_status| is the most important predictor, followed by % |capital_gain|.