Search code examples
pythontensorflowkerasconv-neural-networkshap

Which Shap-Explainer fits my requirements


i have created a CNN with Keras and Tensorflow as my backend and my data consists of 2D images which represent EEG (Electroencephalography)-data from the preprocessed DEAP-Dataset.

I have considered to use SHAP as the model explainer but since there are several shap-explainers (kernel, deep, linear, gradient...) I am not sure which one fits my needs the most or if even SHAP could be helpful in my case. Since my images (Dimensions:40x100x1, the third dimension comes from np.expand_dims, since keras needs 3D images) have no colors, is SHAP even a considerable approach?

Snippet of one item in my dataset

[[[ 3.10000000e+01]
[ 3.00000000e+01]
[-1.14638321e-01]

[ 1.24121500e+02]
[ 3.11109855e+00]
[-1.93024874e-01]]
...
[[ 3.10000000e+01]
[ 3.00000000e+01]
[-6.61770462e-02]]]

Plotting the obove item from my dataset

enter image description here

Hope someone could help me out or point me into the right direction, thank you!


Solution

  • There are no limitations to the use of SHAP for model explanations as they are literally meant to

    explain the output of any machine learning model

    (compare with the docs)

    There are indeed several core explainers available. But they are optimized for different kinds of models. Since your case consists of a CNN model built with TensorFlow and Keras, you might want to consider the following two as your primary options:

    • DeepExplainer: meant to approximate SHAP values for deep learning models.

    • GradientExplainer: explains a model using expected gradients (an extension of integrated gradients).

    Both of these core explainers are meant to be used with Deep Learning models, in particular such built in TensorFlow and Keras. The difference between them is how they approximate the SHAP values internally (you can read more about the underlying methods by following the respective link). Because of this, they will very likely not return the exact same result. However, it is fair to assume that there won't be any dramatic differences (although there is no guarantee).

    While the former two are the primary options, you might still want to check the other core explainers as well. For example, the KernelExplainer can be used on any model and thus, could also be an option on Deep Learning models. But as mentioned earlier, the former two are particularly meant for Deep Learning models and should therefore (probably) be preferred.

    Since you are using pictures as input, you might find the image_plot useful. Usage examples can be found on the GitHub repository you already linked to. You also do not need to worry about colors as they do not matter (see the DeepExplainer MNIST example).