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

Crash when using ShapExplainer wtih RegressionModel and static covariates #1802

Closed
vsantosu opened this issue May 27, 2023 · 4 comments
Closed
Labels
bug Something isn't working triage Issue waiting for triaging

Comments

@vsantosu
Copy link

Describe the bug

When using:

series = series.with_static_covariates(static_covariates)

and shap_explain = ShapExplainer(model)

I get the following error:

Traceback (most recent call last):
  File "models/train_forecast_model.py", line 276, in <module>
    train_model()
  File "models/train_forecast_model.py", line 176, in train_model
    shap_explain = ShapExplainer(model)
  File "/home/user/.virtualenvs/myenv/lib/python3.8/site-packages/darts/explainability/shap_explainer.py", line 173, in __init__
    self.explainers = _RegressionShapExplainers(
  File "/home/user/.virtualenvs/myenv/lib/python3.8/site-packages/darts/explainability/shap_explainer.py", line 557, in __init__
    self.explainers = self._build_explainer_sklearn(
  File "/home/user/.virtualenvs/myenv/lib/python3.8/site-packages/darts/explainability/shap_explainer.py", line 661, in _build_explainer_sklearn
    explainer = shap.LinearExplainer(model_sklearn, background_X, **kwargs)
  File "/home/user/.virtualenvs/myenv/lib/python3.8/site-packages/shap/explainers/_linear.py", line 148, in __init__
    self.expected_value = np.dot(self.coef, self.mean) + self.intercept
  File "<__array_function__ internals>", line 5, in dot
ValueError: shapes (809,) and (21,) not aligned: 809 (dim 0) != 21 (dim 0)

This does not happen when NOT using static covariates...

Expected behavior
It supposed to show the plot as usual.

System (please complete the following information):

  • Python version: python3.8
  • darts version 0.24.0

Additional context
I'm also using past covariates and ShapExplainer works well with those, the error happens when I add the static covariates.

@vsantosu vsantosu added bug Something isn't working triage Issue waiting for triaging labels May 27, 2023
@dennisbader
Copy link
Collaborator

Hi @vsantosu, and thanks for writing. Yes, ShapExplainer currently doesn't support static covariates. We're working on this in #1732.

@vsantosu
Copy link
Author

Thanks so much @dennisbader !! Great work btw! this is a very powerful project.

@dennisbader
Copy link
Collaborator

Thanks @vsantosu, that's great to hear :)

@madtoinou
Copy link
Collaborator

Fixed by #1803, which will be part of the next release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working triage Issue waiting for triaging
Projects
None yet
Development

No branches or pull requests

3 participants