# How to understand RandomForestExplainer output (R package)

I have the following code, which basically try to predict the Species from iris data using randomForest. What I'm really intersed in is to find what are the best features (variable) that explain the species classification. I found the package randomForestExplainer is the best to serve the purpose.

library(randomForest)
library(randomForestExplainer)
forest <- randomForest::randomForest(Species ~ ., data = iris, localImp = TRUE)
importance_frame <- randomForestExplainer::measure_importance(forest)
randomForestExplainer::plot_multi_way_importance(importance_frame, size_measure = "no_of_nodes")


The result of the code produce this plot: Based on the plot, the key factor to explain why Petal.Length and Petal.Width is the best factor are these (the explanation is based on the vignette):

1. mean_min_depth – mean minimal depth calculated in one of three ways specified by the parameter mean_sample,
2. times_a_root – total number of trees in which Xj is used for splitting the root node (i.e., the whole sample is divided into two based on the value of Xj),
3. no_of_nodes – total number of nodes that use Xj for splitting (it is usually equal to no_of_trees if trees are shallow),

It's not entirely clear to me why the high times_a_root and no_of_nodes is better? And low mean_min_depth is better?

What are the intuitive explanation for that?

The vignette information doesn't help.

## 1 Answer

At each node, a subset of the full set of predictors is evaluated for their strength of association with the dependent variable. The strength of association may be measured using a correlation coefficient, or some other metric (necessary if there are both categorical or continuous predictors). The most strongly associated predictor is then used to split the data.

This implies that variables that occur closer to the root are more important, in the sense that they are most strongly associated with the dependent variable in each of the bootstrap data subsets. times_a_root and the mean_min_depth are straightforward ways of measuring importance in this sense: a variable that is closer to the root, or one that on average occurs closer to the root, is one that is strongly associated with the dependent variable.

no_of_nodes is distinct from the other two. Picture the dependent variable being a strong sinusoidal function of one predictor. The predictor will not necessarily appear as being important on the previous two metrics because of the lack of a clear trend/direction/non-zero linear slope in a bivariate plot. However, eventually the trees will start to split on this predictor, and will then continue to split on it a very large number of times to approximate the sinusoidal function.no_of_nodes will capture the importance of this and (I suspect) other nonlinear predictors (without a clear trend/direction/non-zero linear slope) better than the earlier metrics.

That said, I think that accuracy_decrease (for classification) and mse_increase (for regression) are far better metrics of importance than the rest. They measure the decrease in the forest's predictive performance if a particular predictor is permuted. Correlated predictors will influence this, but they will also affect the other importance metrics as well. And whether that matters depends on what your goals for the analysis are.

• thanks for explanation. There are times where accuracy_decrease is negative. What does it mean? Good or bad? – neversaint Apr 19 '18 at 6:40
• You can think of it as contributing basically zero predictive power in those cases. The model might improve a tiny bit when you exclude it but not by much (for reasons I explain here: stats.stackexchange.com/a/288762/121522). – mkt - Reinstate Monica Apr 19 '18 at 7:00
• Excellent explanation thanks! – Simon Woodward May 14 '19 at 19:58