2
$\begingroup$

The randomForest package in R has the importance() function to get both node impurity and mean premutation importance for variables. Why, when calculating mean permutation importance, do the results not sum to 100%?

Here's a simple reproducible example:

library(randomForest)
data(iris)
iris.rf <- randomForest(Species~., importance = TRUE, data = iris, ntrees=1000)
imp <- importance(iris.rf, type = 1)
sum_imp <- sum(imp)
sum_imp     # != 100

Thanks

$\endgroup$
2

2 Answers 2

6
$\begingroup$

As far as I can tell, variable importance is measuring either: a) the percentage that the prediction error increases when the variable is removed, or b) the change in the purity of each node when the variable is removed. (Averaged over all trees in the forest.) Neither of these is a probability, so there's no reason they should add up to 100%.

You can, of course, divide by the sum of all importances to get a percentage, but I think that would create confusion: you now have a percentage of what exactly?

(Welcome to the site!)

$\endgroup$
0
3
$\begingroup$

I'm guessing you're used to scikit-learn's random forest implementation, which normalizes the feature importances so that they sum to 1 (as they explain in the documentation). Summing to 1 isn't a natural property of random forest feature importances though (regardless of which feature importance metric you use) and R doesn't normalize them the way scikit-learn does. You can always do that as a post-processing step if you'd like, though!

If you're curious, here's a guide to the different random forest feature importance metrics: https://explained.ai/rf-importance.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.