Local Variable Importance - Random Forest

Hi All,

I wanted to generate a labelled horizontal barplot using within-class local variable importance. I wondered if it would be possible for someone to demonstrate this using the following code below?

This code was supplied by the author of the 'ranger' package on the following link: variable importance by class · Issue #552 · imbs-hl/ranger · GitHub.

With this in mind, I wondered if it was possible for someone to demonstrate local variable variable importance for one of the classes below.

All help would be appreciated, thanks.

rf <- ranger(Species ~ ., iris, importance = "permutation", 
             local.importance = TRUE)

colMeans(rf$variable.importance.local[iris$Species == "setosa", ])
colMeans(rf$variable.importance.local[iris$Species == "versicolor", ])
colMeans(rf$variable.importance.local[iris$Species == "virginica", ]


rf <- ranger(Species ~ ., iris,
  importance = "permutation",
  local.importance = TRUE

(setosa_imp_df <- enframe(colMeans(
  rf$variable.importance.local[iris$Species == "setosa", ]

ggplot(data=setosa_imp_df) + 
      y=value) +
  geom_col() + 
ggtitle("setosa local importance of rf")

Thank you @nirgrahamuk . The 'enframe' function worked perfectly. Thanks for your help

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.