giuseppec / iml

iml: interpretable machine learning R package
https://giuseppec.github.io/iml/
Other
492 stars 88 forks source link

Problems with single-predictor models #81

Open mstaniak opened 5 years ago

mstaniak commented 5 years ago

I'm running some toy examples like the one below:

set.seed(17)
x <- runif(1000, -10, 10)
y <- 0.05*x^2
quadratic <- data.frame(x = x,
                        y = y)
true_model <- function(model, newdata) 0.05*(newdata$x)^2

library(iml)
mp = Predictor$new(list(), data = quadratic[, "x", drop = FALSE],
                   predict.fun = true_model)
shapley = Shapley$new(mp, x.interest = data.frame(x = -6))

lime_expl_iml <- LocalModel$new(mp, x.interest = data.frame(x = -6), k = 1)

and both calls (Shapley$new and LocalModel$new) results in an error when there is just a single predictor. The errors are:

Assertion on 'prediction' failed: Must have exactly 1 rows, but has 0 rows.

Error in self$predictor$data$match_cols(data.frame(newdata)) : 
  Missing columns: V1

I'm aware that it's an unusual setting, but playing with such simple models is very instructive.

christophM commented 5 years ago

I excluded the case where there is only one predictor, since none of the interpretation methods is meaningful in that case. It should throw a more meaningful error though.