giuseppec / giuseppec/iml

fix xlim for pdp/ice plots when using grid.points

Open
#161 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
R
Stars
503
Forks
87
PR merge metrics
No merged PRs in 30d

Description

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 :)

![image](https://user-images.githubusercontent.com/40632799/105693971-afdbfa00-5f00-11eb-8683-8eb7a73a4b03.png)

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))

```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.