Closed jmpanfil closed 5 years ago
the problem is that the prediction function for xgboost needs a xgb.DMatrix and not a data.frame.
try this:
predict.fun=function(object, newdata){ newData_x = xgb.DMatrix(data.matrix(newdata), missing = NA) results<-predict(model, newData_x) return(results) }
Thanks @keithhurley
Apologies for my late response. Using @keithhurley solution appears to be working except I am getting a large amount of warnings.
lime <- LocalModel$new(predictor, x.interest = x[1,], k = 20)
There were 50 or more warnings (use warnings() to see the first 50)
warnings()
Warning messages:
1: In gower_work(x = x, y = y, pair_x = pair_x, pair_y = pair_y, ... :
skipping variable with zero or non-finite range.
That warning repeats however many times.
the problem is that the prediction function for xgboost needs a xgb.DMatrix and not a data.frame.
try this:
predict.fun=function(object, newdata){ newData_x = xgb.DMatrix(data.matrix(newdata), missing = NA) results<-predict(model, newData_x) return(results) }
Thanks for providing this work-around. Minor thing in predict.fun()
- I think the function parameters should be function(model, newdata)
to reflect the predict()
call within the function.
Is there a workaround to implement the Shapley function, for example, on xgboost models trained on xgb.DMatrix objects?
For example,
results in an error: