【发布时间】:2021-07-14 06:32:05
【问题描述】:
我有一个带有 2 个目标变量的 tensorflow 模型,我想查看其 SHAP 值如下:
import pandas as pd
import tensorflow as tf
import shap
x_df = pd.DataFrame({'var1':[4, 6, 19, 8],
'var2':[7, 21, 5, 12],
'var3':[11, 15, 19, 5],
'var4':[8, 1, 16, 18]})
target_var = pd.DataFrame({'y1': [12, 4, 6, 8],
'y2': [11, 13, 9, 12]})
model = tf.keras.models.Sequential([
tf.keras.layers.Dense(4, activation='sigmoid'),
tf.keras.layers.Dense(2)])
model.compile(optimizer='adam', loss="mse")
model.fit(x_df.values, target_var, epochs=1, batch_size=2)
explainer = shap.DeepExplainer(model, x_df)
shap_values = explainer.shap_values(x_df)
shap.summary_plot(shap_values, x_df)
我使用了几个教程来解释我可以将tf 模型直接插入解释器并使用它,但是.shap 值返回如下错误:
AttributeError: 'tuple' object has no attribute 'rank'
任何帮助都会很棒,在此先感谢!
【问题讨论】:
标签: python tensorflow shap