问题
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