CNN模型中不同类型输入的SHAP解释

时间:2020-01-16 15:40:23

标签: shap

我有一个问题要使用SHAP来解释CNN模型的结果。我的CNN模型采用2种不同类型的输入。一个是图像,另一个是特征向量。我通过考虑这两个因素对模型进行了训练和测试。建立模型没问题。

当我尝试使用SHAP来同时解释这两个输入的结果时,它不起作用。我实际上已经尝试了deepexplainer和gradientexplaner。我收到的错误如下:

文件“”,第1行,在 shap_values =说明者.shap_values([x_test [:3],feature_test [:3]])

文件“ C:\ Users \ kaz10003 \ AppData \ Local \ Continuum \ anaconda3 \ lib \ site->> packages \ shap \ explainers \ deep_init_.py”,第119行,在shap_values中 返回self.explainer.shap_values(X,rank_outputs,output_rank_order)

文件“ C:\ Users \ kaz10003 \ AppData \ Local \ Continuum \ anaconda3 \ lib \ site->包\ shap \ explainers \ deep \ deep_tf.py”,第284行,在shap_values中 diffs = model_output [:, l]-self.expected_value [l]-> output_phis [l] .sum(axis = tuple(range(1,output_phis [l] .ndim)))

AttributeError:“列表”对象没有属性“和”

任何人都知道SHAP是否支持这种实现吗?这是我的代码:

n_features = 10
input_feat = Input((n_features,))
input_tensor = Input(shape=(50,60, 1))

c3 = Conv2D(32, (3, 3), activation='relu', padding='same') (input_tensor)
c3 = Conv2D(32, (3, 3), activation='relu', padding='same') (c3)
c3 = Conv2D(32, (3, 3), activation='relu', padding='same') (c3)
p3 = MaxPooling2D((2, 2)) (c3)

f_repeat = RepeatVector(6*7)(input_feat)
f_conv = Reshape((6, 7, n_features))(f_repeat)
p3_feat = concatenate([p3, f_conv], -1)

c3 = Flatten()(p3_feat)
c3 = Dense(512)(c3)
outputs = Dense(2, activation='softmax')(c3)
model = Model(inputs=[input_tensor, input_feat], outputs=[outputs])

model.summary()

explainer = shap.GradientExplainer(model, [x_train, feature_train])
shap_values = explainer.shap_values([x_test[:3], feature_test[:3]])

0 个答案:

没有答案