So I am trying to use LIME to understand predictions from a logit model in R. I know I don't 'need' to, but I am trying to illustrate what it does with a model that one can simply understand as a starting point for a presentation.
But I am having troubles getting this working. I am sure it is due to the model.predict aspect, but my few solutions have not worked.
Basically here is what I would like to do:
model.logit <- glm(formula = formula, data = build.dat, family = binomial(link = "logit"))
train.x <- build.dat[ , all.vars(formula[[3]])]
test.x <- reject.dat[1:100, all.vars(formula[[3]])]
explainer <- lime(train.x, as_classifier(model.logit ), n_bins = 20, quantile_bins = TRUE)
explain.me <- lime::explain(test.x[2 , ], explainer, n_labels = 1, n_features = 8, n_permutations = 5000,
feature_select = "forward_selection", type = "response" )
Now I get the error
Error in match.arg(type) :'arg' should be one of “link”, “response”, “terms”
But moving my 'type = "response"' within the 'lime' code does not fix it.
And I have tried creating a function 'predict_model.glm' with what I thought might correct this due to what I thought was going on when I was using randomForest and got it working:
predict_model.glm <- function(x, newdata, type = "response" ) {
res <- as.data.frame(c(predict(x, newdata = newdata, type = type), 1-predict(x, newdata = newdata, type = type)))
}
But this only seemed to add errors.
I am sure this is due to my missing what exactly the 'lime' aspect is looking for (thus my failure at correcting this with the 'predict_model.glm' function), but I cannot seem to find clarification anywhere.
Any help would be great, Thanks!