Error in case_res[i, , drop = FALSE] : incorrect number of dimensions
mstaniak opened this issue · comments
Mateusz Staniak commented
Linear regression doesn't need LIME, but it's nice to play around with it to get an idea about the explanations. There is a small problem with lm (without mlr) models:
x1 <- rnorm(500)
x2 <- rnorm(500)
x3 <- rnorm(500)
y <- 4*x1 + 2*x2
X <- data.frame(y = y,
x1 = x1,
x2 = x2,
x3 = x3)
lm_m <- lm(y ~ x1 + x2 + x3, data = X)
library(lime)
lime_wrapper <- lime(X[, -1], model = lm_m)
model_type.lm <- function(x, ...) "regression"
predict_model.lm <- function(x, newdata, type, ...) predict(x, newdata, ...)
lime_explanation_1_0 <- lime::explain(X[4, -1], lime_wrapper,
n_features = 3)
throws an error that can be solved by changing it to
predict_model.lm <- function(x, newdata, type, ...) as.data.frame(predict(x, newdata, ...))
Could this be addressed inside the lime code (maybe some more models have predict functions that behave similary to predict.lm)? (Also, maybe some predicts return data.table or tibble which do not have the drop argument) If not, let's close this issue.
Thomas Lin Pedersen commented
predict_model()
must return a data.frame, not a vector