Shap KernelExplainer doesn't run on GPU

Viewed 515

In Tensorflow 2.4.1 a Sequential neural network is defined. I use Shap.KernelExplainer for feature importance. It takes a very long time to run. Is it possible to run the KernelExplainer via GPU?

import shap

data = shap.kmeans(X_train[X_vars], 5)
explainer = shap.KernelExplainer(model.predict, data, gpu_model=True)
shap_values = explainer.shap_values(X_test[X_vars])
shap_values = shap_values[0]
shap.summary_plot(shap_values, X_test[X_vars], plot_type="bar", plot_size=(15, 10))
1 Answers

There is a GPU-accelerated version of the KernelExplainerin CuML library: cuml.explainer.KernelExplainer. In general, it is time-consuming to run KernelExplainer on a large dataset. So it is recommended to use a subset of the samples and/or features.

There is a method designed specifically for deep learning models, called Deep SHAP, you can use it as follows:

import shap
import numpy as np

background = x_train[np.random.choice(X_train.shape[0], 10, replace=False)]
deep_explainer = shap.DeepExplainer(model, background)
shap_values = deep_explainer.shap_values(X_test[1:5])
Related