Questions tagged [shap]

SHAP (SHapley Additive exPlanations) is a unified approach to explain the output of any machine learning model. SHAP connects game theory with local explanations, uniting several previous methods and representing the only possible consistent and locally accurate additive feature attribution method based on expectations (see the SHAP NIPS paper for details).

172 questions
7
votes
1 answer

Does SHAP in Python support Keras or TensorFlow models while using DeepExplainer?

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…
Yash Sharma
  • 93
  • 1
  • 6
5
votes
1 answer

Feature importance in a binary classification and extracting SHAP values for one of the classes only

Suppose we have a binary classification problem, we have two classes of 1s and 0s as our target. I aim to use a tree classifier to predict 1s and 0s given the features. Further, I can use SHAP values to rank the feature importance that are…
Wiliam
  • 647
  • 4
  • 11
5
votes
1 answer

Error using shap with SimpleRNN sequential model

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…
jgm_GIS
  • 153
  • 7
5
votes
4 answers

Exception in Tkinter callback using SHAP

I'm trying to draw some SHAP plots in Python to gain a deeper understanding of the output of my machine learning models. This is the method I'm calling in a for loop: def plotAndSaveSHAPSummary(model,train_data,x_train,pathToSHAPPlots): …
Hagbard
  • 2,139
  • 2
  • 16
  • 42
5
votes
1 answer

Shap statistics

I used shap to determine the feature importance for multiple regression with correlated features. import numpy as np import pandas as pd from sklearn.linear_model import LinearRegression from sklearn.datasets import load_boston import…
Banjo
  • 1,061
  • 1
  • 7
  • 19
4
votes
2 answers

How to customize matplotlib plots using gcf() or gca()?

I am using a package called shap which has a integrated plot function. However i want to adjust some things like the labels, legend, coloring, size etc. apparently due to the developer thats possible via using plt.gcf(). I call the plot like this,…
Quastiat
  • 771
  • 1
  • 7
  • 30
4
votes
1 answer

How to use SHAP with a linear SVC model from sklearn using Pipeline?

I am doing text classification using a linear SVC model from sklearn. Now I want to visualize which words/tokens have the highest impact on the classification decision by using SHAP (https://github.com/slundberg/shap). Right now this does not work…
3
votes
1 answer

None Type is not iterable (RecurrentTabularExplainer)

I'm trying to apply Recurrent Tabular Explainar from LIME, however, I keep on getting the output that NoneType is not iterable. This even persists for this simple minimal example: from lime import lime_tabular x_train = np.random.randint(0, 6249,…
Sunshine
  • 75
  • 7
3
votes
1 answer

shap.Explainer constructor error asking for undocumented positional argument

I'm using the python shap package to better understand my machine learning model. (From the documentation: "SHAP (SHapley Additive exPlanations) is a game theoretic approach to explain the output of any machine learning model." Below is a small…
Joe
  • 33
  • 4
3
votes
0 answers

"LookupError: gradient registry has no entry for: shap_TensorListStack" using DeepExplainer for Keras Model

I am getting the following error when using the DeepExplainer for the Keras sequential model for Multiclass text classification. Please find the details below: ##KERAS VERSION: 2.4.3. ##MODEL model = Sequential() model.add(InputLayer (input_shape=…
3
votes
0 answers

How to save a shap.DeepExplainer (SwigPyObject) to a file?

I tried to save my shap explainer of type DeepExplainer using pickle.dump, but I get the error: can't pickle SwigPyObject objects. My code: my_shap_explainer = DeepExplainer(my_model, background) pickle.dump(my_shap_explainer, my_file) TypeError:…
Miguel de Matos
  • 726
  • 2
  • 9
  • 16
3
votes
1 answer

Negative SHAP values in H2O in Python using predict_contributions

I have been trying to compute SHAP values for a Gradient Boosting Classifier in H2O module in Python. Below there is the adapted example in the documentation for the predict_contibutions method (adapted from…
3
votes
2 answers

How to plot specific features on SHAP summary plots?

I am currently trying to plot a set of specific features on a SHAP summary plot. However, I am struggling to find the code necessary to do so. When looking at the source code on Github, the summary_plot function does seem to have a 'features'…
3
votes
1 answer

Shap value dimensions are different for RandomForest and XGB why/how? Is there something one can do about this?

The SHAP values returned from tree explainer's .shap_values(some_data) gives different dimensions/results for XGB as for random forest. I've tried looking into it, but can't seem to find why or how, or an explanation in any of Slundberg's (SHAP…
D00dood
  • 183
  • 8
3
votes
1 answer

Shap LSTM (Keras, TensorFlow) ValueError: shape mismatch: objects cannot be broadcast to a single shape

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 import numpy as np import tensorflow as tf from…
stringCode
  • 2,174
  • 1
  • 19
  • 32
1
2 3
11 12