SHAP - 统一的方法解释任何机器学习模型的输出


MIT
跨平台
Python

软件简介

SHAP(SHapley Additive exPlanations)以一种统一的方法来解释任何机器学习模型的输出。
SHAP将博弈论与局部解释联系起来,将以前的几种方法结合起来,并根据预期表示唯一可能的一致且局部准确的加法特征归因方法(详见SHAP NIPS
paper
论文)。

虽然SHAP值可以解释任何机器学习模型的输出,但我们已经开发了一种用于树集合方法的高速精确算法(Tree SHAP arXiv paper)。
XGBoost,LightGBM,CatBoost和scikit-learn树模型支持快速C ++实现:

import xgboost
import shap

# load JS visualization code to notebook
shap.initjs()

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

# explain the model's predictions using SHAP values
# (same syntax works for LightGBM, CatBoost, and scikit-learn models)
explainer = shap.TreeExplainer(model)
shap_values = explainer.shap_values(X)

# visualize the first prediction's explanation (use matplotlib=True to avoid Javascript)
shap.force_plot(explainer.expected_value, shap_values[0,:], X.iloc[0,:])