-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
All shap values were NA. #73
Comments
rf is a Multiclass classification model,Can you tell me how to calculate the shap value? Thank you vary much! |
Hi @hyr13579 thank you for posting an issue. However, without a reproducible example to run on my end, I can’t do much to help diagnose your issue. Please post a fully reproducible example and consider using the reprex package. |
Thank you. I changed the code. It worked. |
Glad you got it to work! |
library(fastshap)
train_data <- as.data.frame(train_data)
shap <- explain(
rf,
X = as.data.frame(train_data),
nsim = 1,
adjust = FALSE,
shap_only = TRUE,
pred_wrapper = function(model,newdata){
as.data.frame(predict(model,newdata) ) %>% pull(1)
}
)
When I run the above code, all the shap values I get are NA.There are a lot of warniings.
Warnings ( )
1: In Ops.factor(pred_wrapper(object, newdata = B[[1L]]), ... :
‘-’ not meaningful for factors
2: In Ops.factor(pred_wrapper(object, newdata = B[[1L]]), ... :
‘-’ not meaningful for factors
3: In Ops.factor(pred_wrapper(object, newdata = B[[1L]]), ... :
‘-’ not meaningful for factors
4: In Ops.factor(pred_wrapper(object, newdata = B[[1L]]), ... :
‘-’ not meaningful for factors
5: In Ops.factor(pred_wrapper(object, newdata = B[[1L]]), ... :
‘-’ not meaningful for factors
6: In Ops.factor(pred_wrapper(object, newdata = B[[1L]]), ... :
‘-’ not meaningful for factors
7: In Ops.factor(pred_wrapper(object, newdata = B[[1L]]), ... :
‘-’ not meaningful for factors
8: In Ops.factor(pred_wrapper(object, newdata = B[[1L]]), ... :
‘-’ not meaningful for factors
9: In Ops.factor(pred_wrapper(object, newdata = B[[1L]]), ... :
‘-’ not meaningful for factors
10: In Ops.factor(pred_wrapper(object, newdata = B[[1L]]), ... :
‘-’ not meaningful for factors
11: In Ops.factor(pred_wrapper(object, newdata = B[[1L]]), ... :
‘-’ not meaningful for factors
12: In Ops.factor(pred_wrapper(object, newdata = B[[1L]]), ... :
‘-’ not meaningful for factors
13: In Ops.factor(pred_wrapper(object, newdata = B[[1L]]), ... :
‘-’ not meaningful for factors
14: In Ops.factor(pred_wrapper(object, newdata = B[[1L]]), ... :
‘-’ not meaningful for factors
15: In Ops.factor(pred_wrapper(object, newdata = B[[1L]]), ... :
‘-’ not meaningful for factors
16: In Ops.factor(pred_wrapper(object, newdata = B[[1L]]), ... :
‘-’ not meaningful for factors
17: In Ops.factor(pred_wrapper(object, newdata = B[[1L]]), ... :
‘-’ not meaningful for factors
18: In Ops.factor(pred_wrapper(object, newdata = B[[1L]]), ... :
‘-’ not meaningful for factors
19: In Ops.factor(pred_wrapper(object, newdata = B[[1L]]), ... :
‘-’ not meaningful for factors
20: In Ops.factor(pred_wrapper(object, newdata = B[[1L]]), ... :
‘-’ not meaningful for factors
21: In Ops.factor(pred_wrapper(object, newdata = B[[1L]]), ... :
‘-’ not meaningful for factors
22: In Ops.factor(pred_wrapper(object, newdata = B[[1L]]), ... :
‘-’ not meaningful for factors
23: In Ops.factor(pred_wrapper(object, newdata = B[[1L]]), ... :
‘-’ not meaningful for factors
24: In Ops.factor(pred_wrapper(object, newdata = B[[1L]]), ... :
‘-’ not meaningful for factors
25: In Ops.factor(pred_wrapper(object, newdata = B[[1L]]), ... :
‘-’ not meaningful for factors
26: In Ops.factor(pred_wrapper(object, newdata = B[[1L]]), ... :
‘-’ not meaningful for factors
27: In Ops.factor(pred_wrapper(object, newdata = B[[1L]]), ... :
‘-’ not meaningful for factors
28: In Ops.factor(pred_wrapper(object, newdata = B[[1L]]), ... :
‘-’ not meaningful for factors
29: In Ops.factor(pred_wrapper(object, newdata = B[[1L]]), ... :
‘-’ not meaningful for factors
30: In Ops.factor(pred_wrapper(object, newdata = B[[1L]]), ... :
‘-’ not meaningful for factors
31: In Ops.factor(pred_wrapper(object, newdata = B[[1L]]), ... :
‘-’ not meaningful for factors
32: In Ops.factor(pred_wrapper(object, newdata = B[[1L]]), ... :
‘-’ not meaningful for factors
33: In Ops.factor(pred_wrapper(object, newdata = B[[1L]]), ... :
‘-’ not meaningful for factors
34: In Ops.factor(pred_wrapper(object, newdata = B[[1L]]), ... :
‘-’ not meaningful for factors
35: In Ops.factor(pred_wrapper(object, newdata = B[[1L]]), ... :
‘-’ not meaningful for factors
36: In Ops.factor(pred_wrapper(object, newdata = B[[1L]]), ... :
‘-’ not meaningful for factors
37: In Ops.factor(pred_wrapper(object, newdata = B[[1L]]), ... :
‘-’ not meaningful for factors
38: In Ops.factor(pred_wrapper(object, newdata = B[[1L]]), ... :
‘-’ not meaningful for factors
39: In Ops.factor(pred_wrapper(object, newdata = B[[1L]]), ... :
‘-’ not meaningful for factors
40: In Ops.factor(pred_wrapper(object, newdata = B[[1L]]), ... :
‘-’ not meaningful for factors
41: In Ops.factor(pred_wrapper(object, newdata = B[[1L]]), ... :
‘-’ not meaningful for factors
42: In Ops.factor(pred_wrapper(object, newdata = B[[1L]]), ... :
‘-’ not meaningful for factors
43: In Ops.factor(pred_wrapper(object, newdata = B[[1L]]), ... :
‘-’ not meaningful for factors
44: In Ops.factor(pred_wrapper(object, newdata = B[[1L]]), ... :
‘-’ not meaningful for factors
45: In Ops.factor(pred_wrapper(object, newdata = B[[1L]]), ... :
‘-’ not meaningful for factors
46: In Ops.factor(pred_wrapper(object, newdata = B[[1L]]), ... :
‘-’ not meaningful for factors
47: In Ops.factor(pred_wrapper(object, newdata = B[[1L]]), ... :
‘-’ not meaningful for factors
48: In Ops.factor(pred_wrapper(object, newdata = B[[1L]]), ... :
‘-’ not meaningful for factors
49: In Ops.factor(pred_wrapper(object, newdata = B[[1L]]), ... :
‘-’ not meaningful for factors
50: In Ops.factor(pred_wrapper(object, newdata = B[[1L]]), ... :
‘-’ not meaningful for factors
The text was updated successfully, but these errors were encountered: