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

Bug when using xgb_model.pred(pred_interactions=True) #464

Closed
kyoungrok0517 opened this issue Feb 27, 2019 · 6 comments
Closed

Bug when using xgb_model.pred(pred_interactions=True) #464

kyoungrok0517 opened this issue Feb 27, 2019 · 6 comments
Labels
bug Indicates an unexpected problem or unintended behaviour

Comments

@kyoungrok0517
Copy link

kyoungrok0517 commented Feb 27, 2019

As suggested in #452 I'm now trying to use the native functionality of xgboost to get the SHAP importance and interaction. I'm posting here presuming the shap team is involved in adding shap into xgboost library.

Problem
I get the following error when I use pred_interactions=True to get the feature interaction.

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-14-6baa08e16bb5> in <module>()
----> 1 preds = model.predict(dtest, pred_contribs=True, approx_contribs=True, pred_interactions=True)

~/anaconda/lib/python3.6/site-packages/xgboost/core.py in predict(self, data, output_margin, ntree_limit, pred_leaf, pred_contribs, approx_contribs, pred_interactions, validate_features)
   1237                     preds = preds.reshape(nrow, data.num_col() + 1, data.num_col() + 1)
   1238                 else:
-> 1239                     preds = preds.reshape(nrow, ngroup, data.num_col() + 1, data.num_col() + 1)
   1240             elif pred_contribs:
   1241                 ngroup = int(chunk_size / (data.num_col() + 1))

ValueError: cannot reshape array of size 148317785 into shape (35255,0,601,601)
@slundberg
Copy link
Collaborator

Does anything change when you use approx_contribs=False?

@kyoungrok0517
Copy link
Author

kyoungrok0517 commented Mar 3, 2019

I'm posting the result of combinations.

  • pred_contribs=True, approx_contribs=False, pred_interactions=True
    • X (the same error)
  • approx_contribs=True, pred_interactions=True
    • O

I'll stick to the second combination of arguments, but I think the result of parameter combination is unpredictable. Hope to be fixed for better usability.

@kyoungrok0517
Copy link
Author

kyoungrok0517 commented Mar 4, 2019

I suspect that the problem occurs when I use objective=multi:softprob with xgboost. unlike multi:softmax that objective produces the probabilities for each class. So if I have 8 classes then the 2nd dimension in the error message will be 8, not 1. Maybe this is causing the problem.

@slundberg slundberg added the bug Indicates an unexpected problem or unintended behaviour label Mar 11, 2019
@slundberg
Copy link
Collaborator

Sorry for the slow reply. This is an issue inside XGBoost, and it looks like ngroup is 0. Which it should not be. If we look at the relevant section in XGBoost it seems like ngroup should never be zero: https://github.com/dmlc/xgboost/blob/6fb4c5efef6a2d5231f7d3e2d40716c2a774ab08/python-package/xgboost/core.py#L1297-L1306

@rnarukulla-deloitte
Copy link

I have the same issue while I am calling the "explainer.shap_values(test_df)". In my case, the model was built using CLI version of Xgboost and loaded using booster.load_model()

@rnarukulla-deloitte
Copy link

I have the same issue while I am calling the "explainer.shap_values(test_df)". In my case, the model was built using CLI version of Xgboost and loaded using booster.load_model()

Hi, This issue is resolved, after a work around..
shap_values = xgb_model.predict(xgb.DMatrix(test_df[xgb_features]), pred_interactions=False, approx_contribs=True )

but, can you help me , How do I calculate explainer.expected_value with this approach..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Indicates an unexpected problem or unintended behaviour
Projects
None yet
Development

No branches or pull requests

3 participants