在jupyter book
运行代码片段
import xgboost
import shap
shap.initjs()
shap.force_plot(explainer.expected_value, shap_values[0,:], X.iloc[0,:])
报错如下:
Visualization omitted, Javascript library not loaded!
Have you runinitjs()
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.
解决方案:
代码改为:
shap.force_plot(explainer.expected_value, shap_values[0,:], x[0,:],matplotlib=True)