You need to enable JavaScript to run this app. 使用SHAP分析GBT分类器时base_value应如何解读?
优惠活动
大模型
产品
解决方案
定价
更多

使用SHAP分析GBT分类器时base_value应如何解读?

关于SHAP force_plot中base_value的相关疑问

最近我接触到一款优秀的机器学习可解释性库SHAP,基于scikit-learn的内置示例数据集构建了简单的XGBoost分类器,尝试绘制force_plot可视化图。

根据该库的说明,force_plot的解读规则如下:

上述解释展示了各个特征如何推动模型输出从base_value(传入的训练集上的平均模型输出)变化到最终的模型输出。推动预测值升高的特征用红色表示,推动预测值降低的特征用蓝色表示(该force图发表于我们的Nature BME论文)。

按照说明,我认为base_value应该和clf.predict(X_train).mean()的计算结果一致,也就是0.637。但实际查看force_plot时发现两者数值并不匹配,这个base_value甚至不在[0,1]区间内。我猜测该数值经过了某种单调变换,尝试了分别以10、自然常数e、2为底取对数的操作,仍未得到匹配结果。请问这个base_value究竟该如何理解?

以下是我用到的代码:

!pip install shap

from sklearn.datasets import load_breast_cancer
from sklearn.model_selection import train_test_split
from sklearn.ensemble import GradientBoostingClassifier
import pandas as pd
import shap

X, y = load_breast_cancer(return_X_y=True)
X = pd.DataFrame(data=X)
y = pd.DataFrame(data=y)

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=0)

clf = GradientBoostingClassifier(random_state=0)
clf.fit(X_train, y_train)

print(clf.predict(X_train).mean())

# 加载JS可视化代码到notebook
shap.initjs()

explainer = shap.TreeExplainer(clf)
shap_values = explainer.shap_values(X_train)

# 可视化第一份样本的预测解释(传入matplotlib=True可避免依赖JS渲染)
shap.force_plot(explainer.expected_value, shap_values[0,:], X_train.iloc[0,:])

内容的提问来源于stack exchange,提问作者G. Macia

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.11.18 23:45:05