How to change the colour of pdp and/or ice plots from the iml package in R?

£可爱£侵袭症+ 提交于 2020-12-15 22:06:13

问题


Below is some sample code to produce a pdp + ice plot for the Boston data using the iml package:

library("randomForest")
library("iml")
library("MASS")
library("ggplot2")

data("Boston") 
rf <- randomForest(medv ~ ., data = Boston, ntree = 50)  # create random forest
mod <- Predictor$new(rf, data = Boston). # get predictions from iml

eff <- FeatureEffect$new(mod, feature = "rm", method = "pdp+ice",grid.size = 30 )

#Create plot:
plot(eff) +
  # Adds original predictions
geom_point(data = Boston, aes(y = mod$predict(Boston)[[1]], x = rm), color = "blue", size = 0.5)

This produces the following plot:

I was wondering if it's possible to change the colour of the gold/yellow pdp curve... and change the colour of the black/grey ICE curves?

I have been looking into it and I have had no luck. As far as im aware the output is a ggplot object, so there should be a way of doing this. But I haven't figured it out yet.

来源:https://stackoverflow.com/questions/61788948/how-to-change-the-colour-of-pdp-and-or-ice-plots-from-the-iml-package-in-r

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!