NorskRegnesentral/shapr

Error for glm and gam models

JensWahl opened this issue · 0 comments

On devel branch using a glm model gives an error due to being of class glm and lm.

library(data.table)
library(shapr)
# Data 
n = 100
beta = c(-0.5, 0.5)
x_train = data.table(matrix(rnorm(n*2), ncol = 2))
dt = data.table(y=y, x_train)
x_test = x_train[1:10, ]
y = rpois(n, exp(as.matrix(x_train) %*% beta))
p = mean(y)

# Model
model = glm(y ~ ., data = dt, family = poisson)

explanation <- explain(
  x_train,
  x_test,
  model = model,
  approach = "empirical",
  prediction_zero = p,
)

Gives the error message

Error in get(paste0("get_model_specs.", model_class0)) : 
  first argument has length > 1
In addition: Warning message:
In if (native_func_available) { :
  the condition has length > 1 and only the first element will be used

which comes from this line in get_feature_specs:

get_model_specs <- get(paste0("get_model_specs.", model_class0))

as a glm model is of class lm and glm.

This will happen with GAMs as well, because they are in addition of class gam.