laz*_*rea 5 python matplotlib databricks azure-databricks shap
我想做一个简单的形状分析并绘制 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.
Run Code Online (Sandbox Code Playgroud)
代码:
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,:])
Run Code Online (Sandbox Code Playgroud)
有什么方法可以在 Databricks 上进行图像绘制工作吗?
Ser*_*nov 16
让我们尝试稍微不同的 ( 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 # <--
)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5778 次 |
| 最近记录: |