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

Explanation API and feature importance for GBM #2564

Merged
merged 13 commits into from
Oct 4, 2022
Merged

Explanation API and feature importance for GBM #2564

merged 13 commits into from
Oct 4, 2022

Conversation

jppgks
Copy link
Contributor

@jppgks jppgks commented Sep 28, 2022

Introduces abstract Explainer class with the following method for explaining model predictions:

def explain(self, **kwargs) -> Tuple[List[Explanation], List[float]]:
    """Explain the model's predictions.

    # Return

    :return: (Tuple[List[Explanation], List[float]]) `(explanations, expected_values)`
        `explanations`: (List[Explanation]) A list of explanations, one for each row in the input data. Each
        explanation contains the feature attributions for each label in the target feature's vocab.

        `expected_values`: (List[float]) of length [output feature cardinality] Expected value for each label in
        the target feature's vocab.
    """

Explanation is a dataclass for storing explanations for a single row of input data.

Additionally:

  • refactors Integrated Gradients as an implementation of the Explainer base class
  • adds GBMExplainer for explaining GBM models using LightGBM feature importance

@github-actions
Copy link

github-actions bot commented Sep 28, 2022

Unit Test Results

         6 files           6 suites   3h 9m 21s ⏱️
  3 428 tests   3 350 ✔️   78 💤 0
10 284 runs  10 027 ✔️ 257 💤 0

Results for commit 14306a5.

♻️ This comment has been updated with latest results.

@jppgks jppgks marked this pull request as ready for review October 3, 2022 13:40
@jppgks jppgks requested review from dantreiman and tgaddair October 3, 2022 13:40
explanation.add(feat_imp)

# TODO:
expected_values.append(0.0)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tgaddair what should the expected values be for GBM?

Copy link
Contributor Author

@jppgks jppgks Oct 3, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From Travis: value of 0 OK for now, can look into this again depending on future visualizations

Copy link
Contributor

@dantreiman dantreiman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks great, very positive improvement toludwig.explain. Made a few optional refactoring suggestions

ludwig/explain/util.py Outdated Show resolved Hide resolved
ludwig/explain/base.py Outdated Show resolved Hide resolved
ludwig/explain/base.py Outdated Show resolved Hide resolved
ludwig/explain/base.py Outdated Show resolved Hide resolved
@jppgks jppgks requested a review from dantreiman October 4, 2022 09:26
Copy link
Contributor

@dantreiman dantreiman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@jppgks jppgks merged commit 1caede3 into master Oct 4, 2022
@jppgks jppgks deleted the gbm-feat-imp branch October 4, 2022 18:20
jppgks added a commit that referenced this pull request Oct 6, 2022
* add docstring for explain_ig

* solidify Explainer API

* add gbm explainer

* add dataclasses for typed explanations

* add GBM feature importance

* remove unused imports

* add tests

* fix test

* extract explanation into file

* rename base to explainer

* remove unused kwargs

* remove device placement from base explainer

* use proper field from gbm
jppgks added a commit that referenced this pull request Oct 6, 2022
* add docstring for explain_ig

* solidify Explainer API

* add gbm explainer

* add dataclasses for typed explanations

* add GBM feature importance

* remove unused imports

* add tests

* fix test

* extract explanation into file

* rename base to explainer

* remove unused kwargs

* remove device placement from base explainer

* use proper field from gbm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants