官方文档:
https://shap-lrjball.readthedocs.io/en/latest/generated/shap.summary_plot.html
简介(还有其他的功能):
https://mp.weixin.qq.com/s/8e-_YQc94NPMheB2aXcOsQ
保存shap的图片:
https://stackoverflow.com/questions/52137579/save-shap-summary-plot-as-pdf-svg
安装:
pip install shap
举例:
import shap
rf = AdaBoostClassifier()
rf = rf.fit(X_train, y_train)
explainer = shap.TreeExplainer(rf)
shap_values = explainer.shap_values(X_test)
shap.summary_plot(shap_values[1], X_test, show=False, feature_names=["sex", "age", "weight"]) # show=False for save
plt.savefig("shap.pdf", format="pdf")
(目前要修改下snap源码来支持adaboost,搜博客 shap不支持adaboost)