iml
iml copied to clipboard
fix xlim for pdp/ice plots when using grid.points
When you manually set grid.points that do not cover the whole range of the feature, the xlim of the plot is still up to the maximal observed value. This might lead to ugly plots that need manual fixing. Maybe plotting only upto the maximal grid point could improve the user experience :)
Reproducible code:
library(mlr3verse)
library(iml)
task <- tsk("spam")
spam <- task$data()
spam <- as.data.frame(spam)
lrn_ranger_tuned = lrn("classif.ranger",
predict_type = "prob",
importance = "impurity",
mtry = 7)
lrn_ranger_tuned$train(task)
rng <- lrn_ranger_tuned$model
pfun <- function(object, newdata) predict(object, data = newdata)$predictions
predictor = Predictor$new(rng,
data = spam[-which(names(spam) == "type")],
y = (spam$type == "spam"),
predict.fun = pfun,
class = "spam")
grid_pts <- seq(min(spam$remove),
quantile(spam$remove, 0.95), length.out = 30)
ice_remove <- FeatureEffect$new(predictor, "remove", center.at = min(spam$remove), method = "pdp+ice", grid.points = grid_pts)
plot(ice_remove)
plot(ice_remove) + xlim(min(spam$remove),
quantile(spam$remove, 0.95))