【问题标题】:Shap KernelExplainer doesn't run on GPUShap KernelExplainer 不在 GPU 上运行
【发布时间】:2021-11-12 10:43:45
【问题描述】:

在 Tensorflow 2.4.1 中定义了一个顺序神经网络。我使用Shap.KernelExplainer 来表示功能重要性。运行需要很长时间。是否可以通过 GPU 运行KernelExplainer

import shap

data = shap.kmeans(X_train[X_vars], 5)
explainer = shap.KernelExplainer(model.predict, data, gpu_model=True)
shap_values = explainer.shap_values(X_test[X_vars])
shap_values = shap_values[0]
shap.summary_plot(shap_values, X_test[X_vars], plot_type="bar", plot_size=(15, 10))

【问题讨论】:

    标签: python tensorflow deep-learning gpu shap


    【解决方案1】:

    KernelExplainerin CuML library: cuml.explainer.KernelExplainer 有一个 GPU 加速版本。通常,在大型数据集上运行 KernelExplainer 非常耗时。因此建议使用样本和/或特征的子集。

    有一种专门为深度学习模型设计的方法,叫做Deep SHAP,可以这样使用:

    import shap
    import numpy as np
    
    background = x_train[np.random.choice(X_train.shape[0], 10, replace=False)]
    deep_explainer = shap.DeepExplainer(model, background)
    shap_values = deep_explainer.shap_values(X_test[1:5])
    

    【讨论】:

      猜你喜欢
      • 2022-07-13
      • 1970-01-01
      • 1970-01-01
      • 2011-12-11
      • 2018-09-11
      • 1970-01-01
      • 2017-12-03
      • 2019-12-11
      • 2016-02-04
      相关资源
      最近更新 更多