thomasp85 / lime

Local Interpretable Model-Agnostic Explanations (R port of original Python package)
https://lime.data-imaginist.com/
Other
486 stars 110 forks source link

Regressor XGboost Lime #114

Open kikilou opened 6 years ago

kikilou commented 6 years ago

Hi!

I'm trying to explain a regression that I've done with the package "xgboost", with LIME, but it doesn't work and I havn't found any example of such code on the Internet. Do you know if that's even possible? Would you have a simple example that is working? I can make it work when it's a classification issue, but not with regression.

I have this error : "Error in xgboost::xgb.DMatrix(as.matrix(newdata)) :'data' has class 'character' and length 120000. 'data' accepts either a numeric matrix or a single filename.". I think that the first argument in the function "explain" is not right but I don't understand what kind of data I should put.

Here is my code, train and test are data.table object and X is the variable to explain :

require(xgboost)
require(Matrix)

train.label <- train$X
test.label <- test$X

library(Matrix)

dtrain <- sparse.model.matrix(X ~ .-1, data=train)
dtest <- sparse.model.matrix(X ~ .-1, data=test)

library(xgboost)

param <- list(objective = "reg:linear",
eval_metric = "rmse",
max_depth = 6,
eta = 0.1,
gammma = 0,
colsample_bytree = 1,
min_child_weight = 1)

set.seed(1234)

system.time(xgb <- xgboost(params = param,
data = dtrain,
label = train.label,
nrounds = 200,
print_every_n = 100,
verbose = 1))
library(lime)
library(caret)

explainer <- lime(train[,-c("X")], model=xgb)

explanation <- explain(test[,-c("X")], explainer, n_features = 5) 

Thank you!

thomasp85 commented 6 years ago

Can I get you to provide a reproducible example? I do not have access to train and test from your code