ModelOriented / randomForestExplainer

A set of tools to understand what is happening inside a Random Forest
https://ModelOriented.github.io/randomForestExplainer/
230 stars 37 forks source link

Request to add features #18

Closed ANUGAR closed 4 years ago

ANUGAR commented 5 years ago

Hello, Is it possible to customize features in the chart obtained with the function "plot_min_depth_distribution" of your package? I'd like to change colors and adjust title. Thanks.

Yue-Jiang commented 5 years ago

plot_min_depth_distribution returns a ggplot object that can be further modified to suit your needs. For example:

set.seed(12345)
rf <- randomForest(Species ~ Petal.Length + Sepal.Length, data = iris, localImp = T)
p <- plot_min_depth_distribution(rf)
p

This is the original plot: image

Now with your custom title and custom color palette:

p + 
  ggtitle("A custom title") + 
  scale_fill_brewer(palette = "Dark2")

image

Can do whatever with it:

p +
  ggtitle("Edge of Tomorty: Rick Die Rickpeat") +
  ggsci::scale_fill_rickandmorty()

image

ANUGAR commented 5 years ago

Thanks for your answer. I am trying now to change the legends of the variables (y axis or in your example change "Pental.Length" or "Sepal.Length" for something else -say without the dot and with a space) of this plot using the scale_y_discrete function, but it does not do anything at all. Which function should I use for this one. Thanks a lot for your attention.

Yue-Jiang commented 5 years ago

There's a coord_flip in the code for plot_min_depth_distribution so instead we need:

p +
  scale_x_discrete(labels = c("Sepal Length", "Petal Length"),
    limits = c("Sepal.Length", "Petal.Length"))

It's important to also include the limits argument so we are sure what we are changing is sane, i.e. not messing up the ordering.

Honestly, I don't think the above features should be included as options for the plotting functions in randomForestExplainer, especially the last one, which would be better served to make the modification in the column names of the input data frame for generating random forests.

image

But definitely good questions worth addressing (by providing code examples to manipulate the ggplot object). Let me know if these meet your needs. If so, I'm going to close this issue.

Yue-Jiang commented 4 years ago

closing since ask has been addressed by code examples.