【发布时间】:2020-05-18 07:56:02
【问题描述】:
您能帮我在不重新启动 Python 内核的情况下使用 Tensorflow 1.15 实现可重现的结果吗?为什么 TF 2.0 和 TF 1.5 的输出结果在参数和数据集完全相同的情况下会有所不同?是否可以实现相同的输出?
更多详情: 我试图通过以下方式解释 TF 2.0 中的模型结果:
import shap
background = df3.iloc[np.random.choice(df3.shape[0], 100, replace=False)]
explainer = shap.DeepExplainer(model, background)
我收到一个错误:
`get_session` is not available when using TensorFlow 2.0.`get_session` is not available when using TensorFlow 2.0.
根据SO topic,我尝试通过在我的代码前面使用来设置 TF 2.0 与 TF 1 的兼容性:
import tensorflow.compat.v1 as tf
但是错误又出现了。 根据许多用户的建议,我将 TF2 降级到 TF 1.15 它解决了问题,并且 shap 模块解释了结果,但是: 1) 为了使结果可重现,我必须在 tf.random.set_random_seed(7) 上更改 tf.random.set_seed(7) 并每次都重新启动 Python 内核!在 TF2 中,我不必重新启动内核。 2) 预测结果发生了变化,尤其是经济效率(即TF1.5.错误分类比TF2.0更重要的样本)。
特遣部队2: 准确度:94.95%,经济效率=64%
TF 1: 准确度:94.85%,经济效率=56%
型号代码为here
【问题讨论】:
标签: python-3.x tensorflow tensorflow2.0 shap