简体   繁体   English

如何使用SHAP解释多类深度学习分类器?

[英]How to interpret multi-class deep learning classifier by using SHAP?

I trained a multi-class classifier in Keras on IRIS data set.我在 Keras 中在 IRIS 数据集上训练了一个多类分类器。 I want to interpret my deep learning model by using SHAP .我想通过使用SHAP来解释我的深度学习模型。 I use the following lines of code where model is my trained neural network classifier, X1[train] is my training input, and X1[test] is my test input:我使用以下代码行,其中模型是我训练的神经网络分类器, X1[train]是我的训练输入, X1[test]是我的测试输入:

import shap
explainer = shap.DeepExplainer(model, X1[train])
shap_values = explainer.shap_values(X1[test])

However, I get this error (I am fine when my softmax has one output in binary classification. The problem appears when softmax has more than 1 output ):但是,我收到此错误(当我的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:

How can I solve this problem and get SHAP values for a single class in multi class deep learning classifier?如何解决这个问题并在多类深度学习分类器中获取单个类的 SHAP 值?

How are you importing keras?你是如何导入keras的? When doing from keras import... I had the same issue, but changing to from tensorflow.keras import ... the DeepExplainer workedfrom keras import...我遇到了同样的问题,但改为from tensorflow.keras import ... DeepExplainer 工作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM