我在 IRIS 数据集上在 Keras 中训练了一个多类分类器。我想通过使用SHAP来解释我的深度学习模型。我使用以下代码行,其中模型是我训练的神经网络分类器,X1[train]
是我的训练输入,X1[test]
是我的测试输入:
import shap
explainer = shap.DeepExplainer(model, X1[train])
shap_values = explainer.shap_values(X1[test])
但是,我得到了这个错误(当我的softmax在二进制分类中有一个输出时我很好。当softmax有超过1个输出时出现问题):
ValueError: Unexpectedly found an instance of type `<class 'numpy.ndarray'>`. Expected a symbolic tensor instance.
During handling of the above exception, another exception occurred:
Layer sequential_96 was called with an input that isn't a symbolic tensor. Received type: <class 'numpy.ndarray'>. Full input:
如何解决此问题并获取多类深度学习分类器中单个类的 SHAP 值?