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

xai init #909

Merged
merged 98 commits into from Oct 4, 2022
Merged

xai init #909

merged 98 commits into from Oct 4, 2022

Conversation

dumjax
Copy link
Contributor

@dumjax dumjax commented Apr 13, 2022

Explanability: Shap with Regression models #609

Summary

First draw of what should be explainability in darts. We use shap library to explain time series, in the case of RegressionModel.

@hrzn hrzn linked an issue Apr 13, 2022 that may be closed by this pull request
Copy link
Contributor

@brunnedu brunnedu left a comment

Choose a reason for hiding this comment

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

Really cool addition to darts! 🚀 Added a few comments, may look at it in more detail later.

darts/explainability/explainability.py Outdated Show resolved Hide resolved
darts/explainability/explainability.py Outdated Show resolved Hide resolved
darts/explainability/explainability.py Outdated Show resolved Hide resolved
darts/explainability/shap_explainer.py Outdated Show resolved Hide resolved
darts/explainability/shap_explainer.py Outdated Show resolved Hide resolved
darts/explainability/shap_explainer.py Outdated Show resolved Hide resolved
darts/explainability/shap_explainer.py Outdated Show resolved Hide resolved
darts/explainability/shap_explainer.py Outdated Show resolved Hide resolved
darts/explainability/explainability.py Outdated Show resolved Hide resolved
darts/explainability/explainability.py Outdated Show resolved Hide resolved
darts/explainability/explainability.py Outdated Show resolved Hide resolved
darts/explainability/explainability.py Show resolved Hide resolved
darts/explainability/explainability.py Outdated Show resolved Hide resolved
darts/explainability/shap_explainer.py Outdated Show resolved Hide resolved
darts/explainability/shap_explainer.py Outdated Show resolved Hide resolved
darts/explainability/shap_explainer.py Outdated Show resolved Hide resolved
darts/explainability/shap_explainer.py Outdated Show resolved Hide resolved
darts/explainability/shap_explainer.py Outdated Show resolved Hide resolved
@hrzn
Copy link
Contributor

hrzn commented Apr 17, 2022

It looks like a great start and I really like the result :) I also like the structure with separate explainer objects of different kinds living in the darts.explainability submodule.

A couple of points:

  • I know it's because it's still a draft, you will have to pay attention to the arguments for each methods. I saw many cases that fail currently (when some argument is None, or not provided for instance).
  • You should rethink a bit what goes in the super-class vs the implementation (I think the super-class should not contain much logic except what is very general and common to all present and future explainers).
  • Writing unit tests will help you catch some of the issues.
  • Also beware of the listing, you should follow the setup here
  • Are you sure you need the class RegressionShapExplainers? I'm wondering if it brings something, as to me it looks like an extra layer and some extra code in a place where we don't really need the encapsulation, as its state is more or less the same as ShapExplainer. But I might be missing something.

@codecov-commenter
Copy link

codecov-commenter commented Apr 20, 2022

Codecov Report

Base: 93.98% // Head: 93.82% // Decreases project coverage by -0.16% ⚠️

Coverage data is based on head (0dee794) compared to base (2988059).
Patch coverage: 90.90% of modified lines in pull request are covered.

❗ Current head 0dee794 differs from pull request most recent head 4915d32. Consider uploading reports for the commit 4915d32 to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #909      +/-   ##
==========================================
- Coverage   93.98%   93.82%   -0.17%     
==========================================
  Files          73       78       +5     
  Lines        8200     8505     +305     
==========================================
+ Hits         7707     7980     +273     
- Misses        493      525      +32     
Impacted Files Coverage Δ
darts/utils/data/encoders.py 98.88% <ø> (ø)
darts/explainability/explainability_result.py 80.00% <80.00%> (ø)
darts/explainability/shap_explainer.py 88.09% <88.09%> (ø)
darts/explainability/explainability.py 96.42% <96.42%> (ø)
darts/explainability/__init__.py 100.00% <100.00%> (ø)
darts/models/forecasting/regression_model.py 98.17% <100.00%> (-0.15%) ⬇️
darts/utils/data/tabularization.py 100.00% <100.00%> (ø)
darts/utils/timeseries_generation.py 96.15% <100.00%> (ø)
darts/timeseries.py 92.34% <0.00%> (-0.06%) ⬇️
...arts/models/forecasting/torch_forecasting_model.py 87.08% <0.00%> (-0.06%) ⬇️
... and 2 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

darts/explainability/explainability.py Show resolved Hide resolved
darts/explainability/explainability.py Outdated Show resolved Hide resolved
darts/explainability/explainability.py Outdated Show resolved Hide resolved
darts/explainability/explainability.py Outdated Show resolved Hide resolved
darts/explainability/explainability.py Outdated Show resolved Hide resolved
darts/explainability/explainability.py Outdated Show resolved Hide resolved
darts/explainability/explainability.py Outdated Show resolved Hide resolved
darts/explainability/explainability.py Outdated Show resolved Hide resolved
darts/explainability/shap_explainer.py Outdated Show resolved Hide resolved
darts/explainability/shap_explainer.py Outdated Show resolved Hide resolved
Copy link
Contributor

@hrzn hrzn left a comment

Choose a reason for hiding this comment

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

It looks great overall @dumjax , nice one!

I have some comments, but mostly unimportant things. The only somewhat important things IMO are

  • Adding unit tests
  • Fixing the case where no past or future covariates are given
  • Improving the docstrings in a few places (I've made small suggestions, but I think we can improve the explanations and formatting in a few places)
  • Factoring out the X/y computation as discussed

I'm really looking forward for us to release it 🚀

darts/explainability/shap_explainer.py Show resolved Hide resolved
darts/explainability/shap_explainer.py Outdated Show resolved Hide resolved
darts/explainability/shap_explainer.py Outdated Show resolved Hide resolved
darts/explainability/shap_explainer.py Outdated Show resolved Hide resolved
darts/explainability/shap_explainer.py Outdated Show resolved Hide resolved
darts/explainability/shap_explainer.py Outdated Show resolved Hide resolved
darts/explainability/shap_explainer.py Show resolved Hide resolved
darts/explainability/shap_explainer.py Show resolved Hide resolved
darts/explainability/shap_explainer.py Outdated Show resolved Hide resolved
darts/explainability/shap_explainer.py Outdated Show resolved Hide resolved
@hrzn hrzn marked this pull request as ready for review September 29, 2022 13:46
Copy link
Contributor

@hrzn hrzn left a comment

Choose a reason for hiding this comment

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

I feel we're 95% there, but there are still a few important things to adapt and to polish before we can merge.
I've made lots of small comments, mainly about the documentation (pls double-check how it renders in HTML before merging), variable naming (I think target_names is confusing, we should use target_components) and also having the horizons start at 1 instead of 0 to be consistent with our forecasting models.

darts/utils/data/encoders.py Outdated Show resolved Hide resolved
darts/explainability/shap_explainer.py Outdated Show resolved Hide resolved
darts/explainability/shap_explainer.py Outdated Show resolved Hide resolved
darts/explainability/shap_explainer.py Outdated Show resolved Hide resolved
darts/explainability/shap_explainer.py Show resolved Hide resolved
darts/explainability/shap_explainer.py Outdated Show resolved Hide resolved
darts/utils/data/tabularization.py Outdated Show resolved Hide resolved
darts/utils/data/tabularization.py Outdated Show resolved Hide resolved
darts/utils/data/tabularization.py Show resolved Hide resolved
dumjax and others added 22 commits September 30, 2022 10:00
Co-authored-by: Julien Herzen <julien@unit8.co>
Co-authored-by: Julien Herzen <julien@unit8.co>
Co-authored-by: Julien Herzen <julien@unit8.co>
Co-authored-by: Julien Herzen <julien@unit8.co>
Co-authored-by: Julien Herzen <julien@unit8.co>
Co-authored-by: Julien Herzen <julien@unit8.co>
Co-authored-by: Julien Herzen <julien@unit8.co>
Co-authored-by: Julien Herzen <julien@unit8.co>
Co-authored-by: Julien Herzen <julien@unit8.co>
Co-authored-by: Julien Herzen <julien@unit8.co>
Co-authored-by: Julien Herzen <julien@unit8.co>
Co-authored-by: Julien Herzen <julien@unit8.co>
Co-authored-by: Julien Herzen <julien@unit8.co>
Co-authored-by: Julien Herzen <julien@unit8.co>
Co-authored-by: Julien Herzen <julien@unit8.co>
Co-authored-by: Julien Herzen <julien@unit8.co>
Co-authored-by: Julien Herzen <julien@unit8.co>
Copy link
Collaborator

@dennisbader dennisbader left a comment

Choose a reason for hiding this comment

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

Looks good, thanks a lot for this!

Comment on lines 149 to 153
) = self.model.encoders.encode_train(
target=background_series,
past_covariate=background_past_covariates,
future_covariate=background_future_covariates,
)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I merged my PR with encoder updates yesterday :) If you apply the two suggestions (with the other suggestion), everything should be up to date!

Suggested change
) = self.model.encoders.encode_train(
target=background_series,
past_covariate=background_past_covariates,
future_covariate=background_future_covariates,
)
) = self.generate_fit_encodings(
series=background_series,
past_covariates=background_past_covariates,
future_covariates=background_future_covariates,
)

@hrzn hrzn merged commit 5424a6d into master Oct 4, 2022
@madtoinou madtoinou deleted the feat/xai branch July 5, 2023 21:55
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.

Explainability: Shap with Regression models
5 participants