-
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
SHAP not working with LSTM! #3344
Comments
Thanks for the report and especially for the reproducing example. I know this is a longstanding issue and I'll look into this in the coming weeks. |
Hi @MohamedNedal. I have encountered the exact same issue in my project. Have you attempted to use any other feature importance algorithm that is compatible with an LSTM? |
So, I have looked into this and am working on a solution. The problem is that with tf version 2 it is not as easy to extract the graph of the model (since tensorflow is just building the graph with lazy execution). I found a solution to catch the graph if we do a forward pass through the model with some example data. But getting this data reliably (conversion of keras tensors to such a form that they can be used to run lazy tf models) is a bit tricky. Will keep you updated if I make further progress. |
Hi @lordegeology , I'm actually not familiar with such tools. I used to find the feature importance via the correlation matrix, but it's not so reliable and limited as it doesn't show the feature importance over time. |
Been having the same issue for a while, and a solution would be greatly appreciated. Thanks @CloseChoice ! |
I found that the LSTM of a lower version of pytorch can get results through shap, but there will still be a warning about an unrecognized model.pyTorch==1.11.0 |
I added a draft PR where the code at least runs through. I suspect that there is still something wrong in how we handle new operations (so basically we ignore them in the custom gradient calculation, which might be wrong), so use the results with caution. Any test cases for this are highly appreciated so feel free to start a review and post them there! Together we can do this! |
Discussed in #3342
Originally posted by MohamedNedal October 16, 2023
Hello, I have a trained LSTM mode for timeseries foreasting and I cannot use
SHAP
with it.I have checked the tutorials and the discussions here on similar problems and I tried those suggestions but still didn't work, unfortunately. ChatGPT couldn't help either as it's something specific to the SHAP routines.
I tried to run the code in another environment with a downgraded TF version, as some suggested, but still didn't work and had more compatibility problems.
My current versions of shap and tensorflow are
Here is a minimal example code to reproduce the error:
The error message:
I would really appreciate your inputs. Thanks in advance!
The text was updated successfully, but these errors were encountered: