-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Fix label option #3636
base: master
Are you sure you want to change the base?
Fix label option #3636
Conversation
fix label option for more than 1 row - convert shap_value to list with compatible dimensions for plotting
Fix label option for more than 1 row
@SFatemehM thanks for the PR, would like to review this. Do you have a code snippet I could use to test this? |
@CloseChoice
So the plot would be like this: Full code snippet:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks pretty good. Since we do not add a unit test I would like to get the notebook
PyTorch Deep Explainer MNIST example
back to work. You transposed the axis of the shap values correctly, could you please add that in the notebook?
And to test that the notebook actually runs, could you please try to remove the notebook from here? Not sure if that works, I guess it'll fail. If this fails, we should add a unit test that this passes and future code changes won't break this
@@ -158,7 +158,8 @@ def image(shap_values: Explanation or np.ndarray, | |||
max_val = np.nanpercentile(abs_vals, 99.9) | |||
for i in range(len(shap_values)): | |||
if labels is not None: | |||
axes[row, i + 1].set_title(labels[row, i], **label_kwargs) | |||
if row==0: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if row==0: | |
if row == 0: |
Just looked at this and I think it would be really good if we could test this function. I hope we can somehow write a test that is shorter than the code you posted but still tests the behaviour. EDIT: I think about either just copying one image array and pasting it into the test and then just create some dummy shap values from there (e.g. set shap values to value x if image value is above y, etc.) but am totally open to suggestions here. Feel free to ping me if you need help with that. Would be great if you could help with this, otherwise I am also willing to just merge your changes |
transpose the axis of test images and shap values
I added |
Yes, that's what I mean. If this does not pass, then that means that the notebook takes too long to execute and I would really like to have a test for the function call you do. |
How about test it with random values? a function like this for example:
Do you think it can help? I can get the plot from this, but if it isn't useful for testing, I'll try and write it as you suggested. |
removed PyTorch Deep Explainer MNIST example.ipynb
I would like to have a test that we can decorate with Then we have something to look at. I guess you could also use the imagenet function to load images |
Fixes label option for more than 1 row
Overview
When there is more than one
pixel_values
as test images inshap.plots.image
and thelabels
option is defined, there will be more than 1 rows in the plot and when setting titles this error rises:It can be fixed by checking
row==0
and setting titles for the first row only.Checklist