Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

The notebook example is not working

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

Nobody has claimed this yet.

Assessment

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

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.

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

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

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.

More from linkedin/FastTreeSHAP

All issues in linkedin/FastTreeSHAP

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.