Skip to content
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

How to calculate SHAP values for simple MLP Neural Network? #1304

Closed
pplonski opened this issue Jul 9, 2020 · 5 comments
Closed

How to calculate SHAP values for simple MLP Neural Network? #1304

pplonski opened this issue Jul 9, 2020 · 5 comments
Labels
stale Indicates that there has been no recent activity on an issue

Comments

@pplonski
Copy link

pplonski commented Jul 9, 2020

I'm building AutoML package where I provide SHAP explanations for different models. I have a problem with SHAP explanations for Neural Networks (issue). The NN that I construct is simple Multi-Layer Perceptron with 2 hidden layers. The computation of SHAP values takes a lot of time (several hours) for very small datasets.

Below simple example:

import numpy as np
import pandas as pd
import keras
import shap
from sklearn import datasets

from keras.optimizers import SGD
from keras.models import Sequential
from keras.layers import Dense

print(keras.__version__) 
print(shap.__version__)

n_features = 10


X, y = datasets.make_classification(
            n_samples=1000,
            n_features=n_features,
            n_informative=4,
            n_redundant=1,
            n_classes=2,
            n_clusters_per_class=3,
            n_repeated=0,
            shuffle=False,
            random_state=0,
        )

model = Sequential()
model.add(Dense(10, activation="relu", input_dim=n_features))
model.add(Dense(10, activation="relu", input_dim=n_features))
model.add(Dense(1, activation="sigmoid"))
model.compile(optimizer=SGD(), loss="binary_crossentropy")
model.fit(X, y)

explainer = shap.KernelExplainer(model.predict_proba, X)
shap_values = explainer.shap_values(X)
keras version = 2.3.1
shap version = 0.35.0

On this simple dataset, computing SHAP values take > 8 hours. What is the faster way to compute the SHAP values? For other algorithms (Xgboost, CatBoost, Extra Tress, LightGBM, Random Forest, Linear Regression) all computations are under 1 minute.

@pplonski pplonski changed the title How to calculated SHAP values for simple MLP Neural Network? How to calculate SHAP values for simple MLP Neural Network? Jul 9, 2020
@pplonski
Copy link
Author

any update on this one

@tkmamidi
Copy link

tkmamidi commented Dec 4, 2020

any update, please?

@Daanielvb
Copy link

In my case, I'm not even able to run the KernelExplainer on a jupyter notebook. It crashed using all the RAM.

I'm using MLP + TF-IDF on a 3000 samples and ~9000 words vocabulary. What do you suggest?

Copy link

This issue has been inactive for two years, so it's been automatically marked as 'stale'.

We value your input! If this issue is still relevant, please leave a comment below. This will remove the 'stale' label and keep it open.

If there's no activity in the next 90 days the issue will be closed.

@github-actions github-actions bot added the stale Indicates that there has been no recent activity on an issue label Jan 18, 2024
Copy link

This issue has been automatically closed due to lack of recent activity.

Your input is important to us! Please feel free to open a new issue if the problem persists or becomes relevant again.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Apr 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale Indicates that there has been no recent activity on an issue
Projects
None yet
Development

No branches or pull requests

3 participants