linkedin / FastTreeSHAP

Fast SHAP value computation for interpreting tree-based models
BSD 2-Clause "Simplified" License
512 stars 31 forks source link

The notebook example is not working #19

Open jpzhangvincent opened 1 year ago

jpzhangvincent commented 1 year ago

I tried to run the notebook example with the following code snippet:

shap_explainer = fasttreeshap.TreeExplainer(lgb_model)
num_leaves = sum(shap_explainer.model.num_nodes) - sum(sum(shap_explainer.model.children_left > 0))
print("Total number of leaves is {}.".format(num_leaves))

But got the error:

AttributeError                            Traceback (most recent call last)
<command-4123838717328114> in <cell line: 2>()
      1 shap_explainer = fasttreeshap.TreeExplainer(lgb_model)
----> 2 num_leaves = sum(shap_explainer.model.num_nodes) - sum(sum(shap_explainer.model.children_left > 0))
      3 print("Total number of leaves is {}.".format(num_leaves))

AttributeError: 'TreeEnsemble' object has no attribute 'num_nodes'

The lightbgm library version is '3.3.5'. Maybe you want to update the notebook correspondingly.

jlyang1990 commented 1 year ago

@jpzhangvincent I just checked and it worked for me on lightgbm v3.3.5. Could you share a full working example of this issue?

CMobley7 commented 1 year ago

I get the same error using lightgbm version 4.0.0