-
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 with TF Encoder Decoder timeseries | AssertionError #3285
Comments
I have same problem.The shap's explainer just can received np.array or pd.dataframe,they are must be regular。If your input have two,and they have not same shape,it can't be convert to np.array or pd.dataframe,and the model will give you a error:data can't be list! |
I am actively working on this, see #3419. Would be great if you could provide an example including the generation of the data so that I can include this as test in the PR and make sure that the issue is fixed. |
I provide a example in #3343 ,if this example can help you fix this issue, I will very proud for this.Thanks again for your work! |
Sorry for the late reply. As an example we can use an online bike dataset, I'll omit any unnecessary steps to keep it clean as much as possible.
The batched and windowed data set can be created using following lines, assuming
create the dataset:
check the shapes:
All shapes are: (batch, time, features) Use and encode decoder LSTM model to train:
Use SHAP
AssertionError: The model output must be a vector or a single value! |
Discussed in #3284
Originally posted by AminDar September 26, 2023
I've been reading the issues on SHAP repository and it seems this question came up couple of times and never been solved completely.
For a LSTM seq2seq timeseries mostly a windowed dataset which is a tf tensor built to feed the data to the model with a shape of [samples, timesteps, features].
As you already see the shape is not a 1D vector and therefore
e = shap.DeepExplainer(model,windowed_test)
will end up with this error:
AssertionError: The model output must be a vector or a single value!
and
shap.GradientExplainer(model,windowed_test)
will end up as:
TypeError: '_PrefetchDataset' object is not subscriptable
So given the model in my case, even when I just want to predict one output (and not a multi step output) I encountered this problem and haven't solved it yet.
The model can be defined as :
and then
I've read 1, 2, 3
but none of them solved my issue or even the original problem.
Specially when you look at the SHAP own example 4 one can immediately see that
It's not a Seq2Seq LSTM for timeseries and
which doesn't follow the encoder/decoder LSTM windowed dataset structure used in timeseries [samples, timesteps, features].
The question is now to see if SHAP can work with encoder decoder seq2seq at all or not?
The text was updated successfully, but these errors were encountered: