gpt4 book ai didi

python - Databricks 上的 Shap 值绘图错误但在本地工作

转载 作者:行者123 更新时间:2023-12-05 09:02:03 34 4
gpt4 key购买 nike

我想做一个简单的形状分析并绘制一个 shap.force_plot。我注意到它在 .ipynb 文件中本地运行没有任何问题,但在 Databricks 上失败并显示以下错误消息:

Visualization omitted, Javascript library not loaded!
Have you run `initjs()` in this notebook? If this notebook was from another user you must
also trust this notebook (File -> Trust notebook). If you are viewing this notebook on
github the Javascript has been stripped for security. If you are using JupyterLab this
error is because a JupyterLab extension has not yet been written.

代码:

import xgboost
import shap

shap.initjs()

X, y = shap.datasets.boston()
bst = xgboost.train({"learning_rate": 0.01}, xgboost.DMatrix(X, label=y), 100)

explainer = shap.TreeExplainer(bst)
shap_values = explainer.shap_values(X)

shap.force_plot(explainer.expected_value, shap_values[0,:], X.iloc[0,:])

有什么方法可以在 Databricks 上绘制图像吗?

最佳答案

让我们尝试稍微不同的 (matplotlib=True):

import xgboost
import shap

X, y = shap.datasets.boston()
bst = xgboost.train({"learning_rate": 0.01}, xgboost.DMatrix(X, label=y), 100)

explainer = shap.TreeExplainer(bst)
shap_values = explainer.shap_values(X)

shap.force_plot(
explainer.expected_value,
shap_values[0,:],
X.iloc[0,:],
matplotlib=True # <--
)

enter image description here

关于python - Databricks 上的 Shap 值绘图错误但在本地工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72112776/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com