Skip to content
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

NaN SHAP values from Booster.predict with pred_contribs=True #3333

Closed
jzakrzew opened this issue May 21, 2018 · 2 comments · Fixed by #3943
Closed

NaN SHAP values from Booster.predict with pred_contribs=True #3333

jzakrzew opened this issue May 21, 2018 · 2 comments · Fixed by #3943

Comments

@jzakrzew
Copy link
Contributor

Environment info

Operating System: Linux

Compiler: gcc 8.1.1

Package used (python/R/jvm/C++): python

xgboost version used: tried both 0.7 and 0.71
python version used: 3.6

Steps to reproduce

run bug.py from nan-contribs.tar.gz to get the following output:

[0.00081278 0.05731808 0.00092801 0.00081278]
[[ 0.0000000e+00 -3.8550010e+00            nan -7.3062401e+00
  -1.5469847e+00  3.7286822e-02 -6.7939714e-02 -2.0173371e-01
   7.2428236e+00]
 [ 0.0000000e+00 -2.9010804e+00            nan -6.2523079e+00
  -4.6626371e-01  2.5810658e-03 -7.5633558e-03 -1.9301096e-01
   7.2428236e+00]
 [ 0.0000000e+00 -3.8550010e+00            nan -7.3062401e+00
  -1.5469847e+00  3.7286822e-02  6.7191636e-03 -2.0173371e-01
   7.2428236e+00]
 [ 0.0000000e+00 -3.8550010e+00            nan -7.3062401e+00
  -1.5469847e+00  3.7286822e-02 -6.7939714e-02 -2.0173371e-01
   7.2428236e+00]]

After some debugging, I discovered that the nans come from the UnwoundPathSum function in
xgboost/include/xgboost/tree_model.h:

total += (unique_path[i].pweight / zero_fraction) / ((unique_depth - i)
/ static_cast<bst_float>(unique_depth + 1));

There, at some point, both unique_path[i].pweight and zero_fraction happen to be zero.

@xydrolase
Copy link
Contributor

Noticed the same issue with certain models.

@slundberg
Copy link
Contributor

@jzakrzew Thanks for getting to the source of the nan's! My guess is we just need to wrap that op in a check for that corner case. I'll look into here soon.

@lock lock bot locked as resolved and limited conversation to collaborators Jun 2, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants