bgreenwell / fastshap

Fast approximate Shapley values in R
https://bgreenwell.github.io/fastshap/
112 stars 18 forks source link

Error in UseMethod("explain") : no applicable method for 'explain' applied to an object of class "xgb.Booster" #32

Closed marboe123 closed 2 years ago

marboe123 commented 2 years ago

Hello,

After fitting a xgboost model I do:

shap_values <- explain(model_n, X = trainval)

I receive this error:

[[Error in UseMethod("explain") : 
  no applicable method for 'explain' applied to an object of class ["xgb.Booster"]]

If I use this line:

shap_values <- fastshap::explain(model_n, X = trainval)

I receive this error:

Error in explain.default(object, feature_names = feature_names, X = X,  : 
  argument "pred_wrapper" is missing, with no default

trainval is a dataframe with traindata. It does not contain the Y values. I have also tried to feed it as matrix although this gives the same error.

Any idea what could be the cause?

Thanks a lot!

marboe123 commented 2 years ago

Addinglibrary(vip) besideslibrary(fastshap)to my code did solve the issue for using shap_values <- fastshap::explain(model_n, X = trainval)