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

Linear explainer with Impute masker fails #1723

Closed
sbushmanov opened this issue Jan 8, 2021 · 2 comments
Closed

Linear explainer with Impute masker fails #1723

sbushmanov opened this issue Jan 8, 2021 · 2 comments
Labels
stale Indicates that there has been no recent activity on an issue

Comments

@sbushmanov
Copy link

Linear explainer with Impute masker will fail due to dimension misalignment in the transform matrices.

To reproduce error:

from shap import Explainer
from shap.datasets import iris
from sklearn.linear_model import LogisticRegression

model = LogisticRegression(max_iter=1000)
model.fit(*iris())

masker = shap.maskers.Impute(data=X_test)

explainer = shap.Explainer(
    model, masker=masker, feature_names=X_train.columns, algorithm="linear"
)
---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<ipython-input-15-82cb4b1256dc> in <module>
      9 
     10 explainer = shap.Explainer(
---> 11     model, masker=masker, feature_names=X_train.columns, algorithm="linear"
     12 )

~/anaconda3/lib/python3.7/site-packages/shap/explainers/_explainer.py in __init__(self, model, masker, link, algorithm, output_names, feature_names, **kwargs)
    165             elif algorithm == "linear":
    166                 self.__class__ = explainers.Linear
--> 167                 explainers.Linear.__init__(self, self.model, self.masker, link=self.link, feature_names=self.feature_names, **kwargs)
    168             else:
    169                 raise Exception("Unknown algorithm type passed: %s!" % algorithm)

~/anaconda3/lib/python3.7/site-packages/shap/explainers/_linear.py in __init__(self, model, masker, link, nsamples, feature_perturbation, **kwargs)
    145             self.mean = self.mean[self.valid_inds]
    146             self.cov = self.cov[:,self.valid_inds][self.valid_inds,:]
--> 147             self.coef = self.coef[self.valid_inds]
    148 
    149             # group perfectly redundant variables together

IndexError: index 3 is out of bounds for axis 0 with size 3
Copy link

This issue has been inactive for two years, so it's been automatically marked as 'stale'.

We value your input! If this issue is still relevant, please leave a comment below. This will remove the 'stale' label and keep it open.

If there's no activity in the next 90 days the issue will be closed.

@github-actions github-actions bot added the stale Indicates that there has been no recent activity on an issue label Feb 12, 2024
Copy link

This issue has been automatically closed due to lack of recent activity.

Your input is important to us! Please feel free to open a new issue if the problem persists or becomes relevant again.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale May 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale Indicates that there has been no recent activity on an issue
Projects
None yet
Development

No branches or pull requests

1 participant