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).

453 questions
6
votes
1 answer

What is the correct way to obtain explanations for predictions using Shap?

I'm new to using shap, so I'm still trying to get my head around it. Basically, I have a simple sklearn.ensemble.RandomForestClassifier fit using model.fit(X_train,y_train), and so on. After training, I'd like to obtain the Shap values to explain…
6
votes
1 answer

The passed model is not callable and cannot be analyzed directly with the given masker! Model: None

When i am using RandomForestRegressor or XGBoost, there is no problem like this. Since i am using Relevance Vector Regression i got this error. from sklearn_rvm import EMRVR model_rvr=EMRVR(kernel="linear").fit(X, y) explainer =…
hersekai
  • 75
  • 1
  • 6
6
votes
0 answers

How are SHAP's feature contributions calculated for models with word embeddings as output?

In a typical Shapley value estimation for a numerical regression task, there is a clear way in which the marginal contribution of an input feature i to the final numerical output variable can be calculated. For input features (age=45, location=’NY’,…
6
votes
1 answer

SHAP values with PyTorch - KernelExplainer vs DeepExplainer

I haven't been able to find much in the way of examples on SHAP values with PyTorch. I've used two techniques to generate SHAP values, however, their results don't appear to agree with each other. SHAP KernelExplainer with PyTorch import torch from…
Cosmicnet
  • 389
  • 4
  • 14
6
votes
1 answer

How to cache a plot in streamlit?

I have built a dashboard in streamlit where you can select a client_ID and have SHAP plots displayed (Waterfall and Force plot) to interpret the prediction of credit default for this client. I also want to display a SHAP summary plot with the whole…
vpvinc
  • 155
  • 2
  • 10
6
votes
2 answers

How to get feature names of shap_values from TreeExplainer?

I am doing a shap tutorial, and attempting to get the shap values for each person in a dataset from sklearn.model_selection import train_test_split import xgboost import shap import numpy as np import pandas as pd import matplotlib.pylab as pl X,y…
con
  • 5,767
  • 8
  • 33
  • 62
6
votes
1 answer

Getting a mistake with shap plotting

X = df.copy() # Save and drop labels y = df['class'] X = X.drop('class', axis=1) cat_features = list(range(0, X.shape[1])) model = CatBoostClassifier(iterations=2000, learning_rate=0.1, random_seed=12) model.fit(X, y, verbose=False,…
hidden layer
  • 81
  • 1
  • 1
  • 6
6
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
  • 201
  • 1
  • 13
6
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
  • 443
  • 2
  • 14
5
votes
1 answer

How do I create shap plot in R for GBM model?

I want to creat a shap plot for feature importance, for GBM model: ctrlCV = trainControl(method = 'repeatedcv', repeats = 5 , number = 10 , classProbs = TRUE , savePredictions = TRUE, summaryFunction = twoClassSummary ) gbmFit = train(CR~., data =…
Kev
  • 375
  • 1
  • 7
5
votes
3 answers

How to output Shap values in probability and make force_plot from binary classifier

I need to plot how each feature impacts the predicted probability for each sample from my LightGBM binary classifier. So I need to output Shap values in probability, instead of normal Shap values. It does not appear to have any options to output in…
zesla
  • 11,155
  • 16
  • 82
  • 147
5
votes
2 answers

SHAP TreeExplainer for RandomForest multiclass: what is shap_values[i]?

I am trying to plot SHAP This is my code rnd_clf is a RandomForestClassifier: import shap explainer = shap.TreeExplainer(rnd_clf) shap_values = explainer.shap_values(X) shap.summary_plot(shap_values[1], X) I understand that shap_values[0] is…
Jaekang Lee
  • 53
  • 1
  • 1
  • 3
5
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…
jessicalfr
  • 69
  • 6
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
  • 3,430
  • 5
  • 28
  • 64
5
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
  • 1,164
  • 1
  • 18
  • 37
1
2
3
30 31