main content

predictor importance estimates by permutation of out-凯发k8网页登录

predictor importance estimates by permutation of out-of-bag predictor observations for random forest of regression trees

description

example

imp = oobpermutedpredictorimportance(mdl) returns a vector of out-of-bag, predictor importance estimates by permutation using the random forest of regression trees mdl. mdl must be a regressionbaggedensemble model object.

example

imp = oobpermutedpredictorimportance(mdl,name,value) uses additional options specified by one or more name,value pair arguments. for example, you can speed up computation using parallel computing or indicate which trees to use in the predictor importance estimation.

input arguments

random forest of regression trees, specified as a regressionbaggedensemble model object created by .

name-value arguments

specify optional pairs of arguments as name1=value1,...,namen=valuen, where name is the argument name and value is the corresponding value. name-value arguments must appear after other arguments, but the order of the pairs does not matter.

before r2021a, use commas to separate each name and value, and enclose name in quotes.

indices of learners to use in predictor importance estimation, specified as the comma-separated pair consisting of 'learners' and a numeric vector of positive integers. values must be at most mdl.numtrained. when oobpermutedpredictorimportance estimates the predictor importance, it includes the learners in mdl.trained(learners) only, where learners is the value of 'learners'.

example: 'learners',[1:2:mdl.numtrained]

parallel computing options, specified as the comma-separated pair consisting of 'options' and a structure array returned by . 'options' requires a parallel computing toolbox™ license.

oobpermutedpredictorimportance uses the 'useparallel' field only. statset('useparallel',true) invokes a pool of workers.

example: 'options',statset('useparallel',true)

output arguments

out-of-bag, predictor importance estimates by permutation, returned as a 1-by-p numeric vector. p is the number of predictor variables in the training data (size(mdl.x,2)). imp(j) is the predictor importance of the predictor mdl.predictornames(j).

examples

load the carsmall data set. consider a model that predicts the mean fuel economy of a car given its acceleration, number of cylinders, engine displacement, horsepower, manufacturer, model year, and weight. consider cylinders, mfg, and model_year as categorical variables.

load carsmall
cylinders = categorical(cylinders);
mfg = categorical(cellstr(mfg));
model_year = categorical(model_year);
x = table(acceleration,cylinders,displacement,horsepower,mfg,...
    model_year,weight,mpg);

you can train a random forest of 500 regression trees using the entire data set.

mdl = fitrensemble(x,'mpg','method','bag','numlearningcycles',500);

fitrensemble uses a default template tree object templatetree() as a weak learner when 'method' is 'bag'. in this example, for reproducibility, specify 'reproducible',true when you create a tree template object, and then use the object as a weak learner.

rng('default') % for reproducibility
t = templatetree('reproducible',true); % for reproducibiliy of random predictor selections
mdl = fitrensemble(x,'mpg','method','bag','numlearningcycles',500,'learners',t);

mdl is a regressionbaggedensemble 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';

figure contains an axes object. the axes object with title out-of-bag permuted predictor importance estimates, xlabel predictors, ylabel estimates contains an object of type bar.

imp is a 1-by-7 vector of predictor importance estimates. larger values indicate predictors that have a greater influence on predictions. in this case, weight is the most important predictor, followed by model_year.

load the carsmall data set. consider a model that predicts the mean fuel economy of a car given its acceleration, number of cylinders, engine displacement, horsepower, manufacturer, model year, and weight. consider cylinders, mfg, and model_year as categorical variables.

load carsmall
cylinders = categorical(cylinders);
mfg = categorical(cellstr(mfg));
model_year = categorical(model_year);
x = table(acceleration,cylinders,displacement,horsepower,mfg,...
    model_year,weight,mpg);

display the number of categories represented in the categorical variables.

numcylinders = numel(categories(cylinders))
numcylinders = 3
nummfg = numel(categories(mfg))
nummfg = 28
nummodelyear = numel(categories(model_year))
nummodelyear = 3

because there are 3 categories only in cylinders and model_year, the standard cart, predictor-splitting algorithm prefers splitting a continuous predictor over these two variables.

train a random forest of 500 regression trees using the entire data set. to grow unbiased trees, specify usage of the curvature test for splitting predictors. because there are missing values in the data, specify usage of surrogate splits. to reproduce random predictor selections, set the seed of the random number generator by using rng and specify 'reproducible',true.

rng('default'); % for reproducibility
t = templatetree('predictorselection','curvature','surrogate','on', ...
    'reproducible',true); % for reproducibility of random predictor selections
mdl = fitrensemble(x,'mpg','method','bag','numlearningcycles',500, ...
    'learners',t);

estimate predictor importance measures by permuting out-of-bag observations. perform calculations in parallel.

options = statset('useparallel',true);
imp = oobpermutedpredictorimportance(mdl,'options',options);
starting parallel pool (parpool) using the 'local' profile ...
connected to the parallel pool (number of workers: 6).

compare the estimates using a bar graph.

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';

in this case, model_year is the most important predictor, followed by cylinders. compare these results to the results in estimate importance of predictors.

more about

tips

when growing a random forest using :

  • standard cart tends to select split predictors containing many distinct values, e.g., continuous variables, over those containing few distinct values, e.g., categorical variables [3]. if the predictor data set is heterogeneous, or if there are predictors that have relatively fewer distinct values than other variables, then consider specifying the curvature or interaction test.

  • trees grown using standard cart are not sensitive to predictor variable interactions. also, such trees are less likely to identify important variables in the presence of many irrelevant predictors than the application of the interaction test. therefore, to account for predictor interactions and identify importance variables in the presence of many irrelevant variables, specify the interaction test [2].

  • if the training data includes many predictors and you want to analyze predictor importance, then specify of the templatetree function as 'all' for the tree learners of the ensemble. otherwise, the software might not select some predictors, underestimating their importance.

for more details, see and .

references

[1] breiman, l., j. friedman, r. olshen, and c. stone. classification and regression trees. boca raton, fl: crc press, 1984.

[2] loh, w.y. “regression trees with unbiased variable selection and interaction detection.” statistica sinica, vol. 12, 2002, pp. 361–386.

[3] loh, w.y. and y.s. shih. “split selection methods for classification trees.” statistica sinica, vol. 7, 1997, pp. 815–840.

extended capabilities

version history

introduced in r2016b

网站地图