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

PartitionShap: channel-first partitioning and channel SHAP plots. #1944

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

ekrell
Copy link

@ekrell ekrell commented Apr 16, 2021

There are a few of us interested in using SHAP to explore the channel-wise contributions. For example, for multispectral satellite imagery or 3D CNNs where the channels are time, temperatures, etc.

To help with initial explorations, I added support for shap/plots/_image.py to display requested channels. For example, if I want to see all RGB bands I can send in [0, 1, 2]. By default, it will sum the channels as before.

I also added a second partition scheme where the channels are split before the the rows and columns. I suspect it will take some time to figure out the best partition schemes and masking methods for these various problems, but hopefully this will be useful for exploring. Again, its an optional parameter that will not affect existing code.

Here is a quick demo: https://github.com/ekrell/shap_multiband/blob/main/MultiChannel_PartitionSHAP_Demo.ipynb

@CCapinha
Copy link

Hi Evan,
this is pretty great! Thanks for putting this forward.
I'm listing below a couple of resources that could bring some broader context and guidance on what/how it could be implemented.

Paper on Deep Learning Interpretability in Time Series Predictions, which seems to perform what is aimed here, but for PyTorch: https://arxiv.org/pdf/2010.13924v1.pdf it also has code here: https://github.com/ayaabdelsalam91/TS-Interpretability-Benchmark

A similar attempt but for Lime: https://github.com/emanuel-metzenthin/Lime-For-Time
(as far as I'm aware, the multivariate/multi-channel implementation is not yet thoroughly tested).

Also this post on a similar aim but for LSTM and Pytorch: https://andrecnf.github.io/2019/07/31/InterpretingRecurrentNeuralNetworksOnMultivariateTimeSeries.html

@ekrell
Copy link
Author

ekrell commented Apr 16, 2021

Thanks for the links! Good weekend reading :)

@eschibli
Copy link

eschibli commented Mar 9, 2022

What would be required to get this merged? I find it very useful and am working to extend it to time series, which I think would be beneficial to the community.

@dsgibbons
Copy link
Collaborator

@ekrell this PR looks interesting. Would you like to raise it over at https://github.com/dsgibbons/shap so we can discuss it further?

@ekrell
Copy link
Author

ekrell commented Jan 6, 2024

This PR is now used in a publication: https://www.cambridge.org/core/journals/environmental-data-science/article/aggregation-strategies-to-improve-xai-for-geoscience-models-that-use-correlated-highdimensional-rasters/F6017A23BEF0BD48969225D68DF819A2

It would be very nice to have it included in the SHAP repo, instead of having to rely on my lab's own fork of a very old version of SHAP.

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.

None yet

4 participants