DeepExplain | unified framework of perturbation | Machine Learning library
kandi X-RAY | DeepExplain Summary
kandi X-RAY | DeepExplain Summary
DeepExplain: attribution methods for Deep Learning [Build Status] === DeepExplain provides a unified framework for state-of-the-art gradient and perturbation-based attribution methods. It can be used by researchers and practitioners for better undertanding the recommended existing models, as well for benchmarking other attribution methods. It supports Tensorflow as well as Keras with Tensorflow backend. Only Tensorflow V1 is supported. For V2, there is an open pull-request, that works if eager execution is disabled.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Runs the perturbation loop
- Evaluate the session
- Check that inputs are compatible
- Converts x to a list
- Run a single batch of data
- Make a list of mini - batches
- Unpack a singleton
- Slice arrays
- Runs the experiment
- Run the optimizer
- The symbolic link of the symbol
- Override nonlinearity gradient
- Calculate the gradients of the given op
- Get activation function
- Reverse gradient op
- Runs the session
DeepExplain Key Features
DeepExplain Examples and Code Snippets
Community Discussions
Trending Discussions on DeepExplain
QUESTION
I'm trying to compute shap values using DeepExplainer, but I get the following error:
keras is no longer supported, please use tf.keras instead
Even though i'm using tf.keras?
...ANSWER
Answered 2021-Jun-14 at 14:52TL;DR
- Add
tf.compat.v1.disable_v2_behavior()
at the top for TF 2.4+- calculate shap values on numpy array, not on df
Full reproducible example:
QUESTION
I tried to use shap in order to do a feature importance analysis. I am using keras and I want to get a bar chart and violin charts. With my DNN, I got something like that: Violin chart bar chart
However, when I tried it with my SimpleRNN, I had problem with the shape. The input shape is (samples,time,features), whereas my output shape is (samples,features). So it is a many-to-one RNN. KernelExplainer, the one that I used in my static models, does not work because of the dimension. DeepExplainer does not work either. It show me this error:
...ANSWER
Answered 2021-May-14 at 21:22I managed to fix it by adding at the beginning of my code
QUESTION
In the code below, I import a saved sparse numpy matrix, created with python, densify it, add a masking, batchnorm and dense ouptput layer to a many to one SimpleRNN. The keras sequential model works fine, however, I am unable to use shap. This is run in Jupyter lab from Winpython 3830 on a Windows 10 desktop. The X matrix has a shape of (4754, 500, 64): 4754 examples with 500 timesteps and 64 variables. I've created a function to simulate the data so the code can be tested. The simulated data returns the same error.
...ANSWER
Answered 2020-Oct-24 at 14:43The owner of the shap repo said:
The fundamental issue here is that DeepExplainer does not yet support TF 2.0.
That was on 11 Dec 2019. Is this still the case? Try it with Tensorflow 1.15 and see if that works.
Another issue on the shap repo about this (2 Jun 2020) says:
Alright, thank you. I did not see the post by Lundberg. I will stick to the workaround of using TF 1.15 until a new version of SHAP is released.
QUESTION
The x_train
looks like this (22 features):
ANSWER
Answered 2020-Aug-12 at 12:36I think SHAP
(whatever it is) is expecting a Numpy array and so indexing x_train
like a Numpy array, it yields an error. Try:
QUESTION
I am currently using SHAP Package to determine the feature contributions. I have used the approach for XGBoost and RandomForest and it worked really well. Since the data I am working on is a sequential data I tried using LSTM and CNN to train the model and then get the feature importance using the SHAP's DeepExplainer
; but it is continuously throwing error. The error I am getting is:
ANSWER
Answered 2020-Apr-30 at 07:05The returned value of model.fit
is not the model instance; rather, it's the history of training (i.e. stats like loss and metric values) as an instance of keras.callbacks.History
class. That's why you get the mentioned error when you pass the returned History
object to shap.DeepExplainer
. Instead, you should pass the model instance itself:
QUESTION
I have an issue with my shap values, here is my model:
...ANSWER
Answered 2020-Apr-07 at 06:26Okay, via reading shap's source code, I realised it didn't take into account that the data were pandas' dataframes, eventhought the documentation says otherwise.
It worked using numpy.arrays
QUESTION
Im trying to plot summary from simple LSTM model. Im getting ValueError: shape mismatch: objects cannot be broadcast to a single shape
when calling shap.summary_plot
. Colab that reproduces the issue
ANSWER
Answered 2020-Mar-30 at 08:39From the documentation, the first two arguments of shap.summary_plot
are:
shap_values
: numpy.array For single output explanations this is a matrix of SHAP values (# samples x # features). For multi-output explanations this is a list of such matrices of SHAP values.
features
: numpy.array or pandas.DataFrame or list Matrix of feature values (# samples x # features) or a feature_names list as shorthand.
In the code that you provided, both shap_vals[0]
and val_x[:10]
have shape (10, 5, 4)
. Therefore, you should either flatten the first and second dimensions or select the timepoint you are interested in. For example:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install DeepExplain
You can use DeepExplain like any standard Python library. You will need to make sure that you have a development environment consisting of a Python distribution including header files, a compiler, pip, and git installed. Make sure that your pip, setuptools, and wheel are up to date. When using pip it is generally recommended to install packages in a virtual environment to avoid changes to the system.
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page