linkedin / linkedin/FastTreeSHAP

The notebook example is not working

Open
#19 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
566
Forks
38
PR merge metrics
No merged PRs in 30d

Description

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)
in ()
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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Locate the notebook example that contains the shown TreeExplainer and num_leaves snippet, then reproduce the AttributeError with LightGBM 3.3.5. Update the example so it runs with that version and verify the notebook completes while reporting the total number of leaves.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
machine-learning
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.