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
Explaining LSTM keras with Eli5 library #294
Comments
I get the same error. Any luck with this? |
@ogreyesp Hey! I think the problem here is that Sci-kit learn expects 2d num arrays for the training dataset for a fit function and the dataset which you are trying to pass here is in the shape of a 3d array. Please try reshaping it to a 2d array. |
I'm running into the same issue. When I reshape training dataset to 2D I will then get an error because my model is expecting a 3D input. `~\Anaconda3\envs\keras-gpu\lib\site-packages\keras\engine\training_utils.py in standardize_input_data(data, names, shapes, check_batch_axis, exception_prefix) ValueError: Error when checking input: expected lstm_5_input to have 3 dimensions, but got array with shape (12, 324)` |
I get the same error. Any luck with this? |
If I am not mistaken, LSTM layers require 3d array, so I don't think eli5 can explain LSTM |
I discovered another library |
@jarrettyeo, I just have a question X_test in both DE.shape_values and summary_plot should have the same shape or they have to have different shape? tf.compat.v1.disable_eager_execution() background = X_train[np.random.choice(X_train.shape[0], 100, replace=False)] DE = shap.DeepExplainer(model, background) # X_train is 3d numpy.ndarray shap.initjs() |
@rebeen I can't remember what shape they need to be in, but here is some of my code from my project which you can adapt: def convert_3d_to_2d(array):
if type(array) != np.ndarray:
raise TypeError("type(array)={} != numpy.ndarray".format(type(array)))
return array.reshape(array.shape[0], array.shape[1] * array.shape[2])
DE = shap.DeepExplainer(model, X_train) # X_train is 3d array
shap_values = DE.shap_values(X_validate, check_additivity=False) # X_validate is 3d array
shap.summary_plot(
convert_3d_to_2d(shap_values[0]), # <- This is probably what you need
X_validate,
feature_names=list_columns
) You didn't mention what problem you were facing but I am guessing it's whether |
Thank you actually I faced this problem `TypeError Traceback (most recent call last) /usr/local/lib/python3.6/dist-packages/shap/plots/summary.py in summary_plot(shap_values, features, feature_names, max_display, plot_type, color, axis_color, title, alpha, show, sort, color_bar, plot_size, layered_violin_max_num_bins, class_names, class_inds, color_bar_label, auto_size_plot) TypeError: only integer scalar arrays can be converted to a scalar index` |
@rebeen Can you open an issue on Stackoverflow and link it here? Then we can avoid hijacking this |
@jarrettyeo Thank you very much I saw your answer on Stackoverflow, also I solved the problem so now I want to run the code properly and let you know about the results |
@rebeen Please do, happy to help |
@jarrettyeo thank you very much, actually, I could not show the screenshot of the results so I sent to your LinkedIn could you please let me know your opinion |
Getting the same, any updates on this? |
Hi, I'm trying to use Eli5 for explaining an LSTM keras model for time series prediction. The keras model receives as input an array with shape (nsamples, timesteps, nfeatures).
This is my code:
So far, everything is ok. The problem is when I execute the following line that launchs an error:
Note: X_train has a shape equal to (nsamples, timesteps, nfeatures) and y_train has a shape (nsamples)
perm = PermutationImportance(my_model, random_state=1).fit(X_train, y_train)
What can I do to fix this error? How can I use eli5 with my LSTM Keras Model?
Bets regards
The text was updated successfully, but these errors were encountered: