【问题标题】:How to calculate joint feature contribution for XGBoost Classifier in python?如何在 python 中计算 XGBoost 分类器的联合特征贡献?
【发布时间】:2020-05-19 14:06:17
【问题描述】:

我参考了http://savvastjortjoglou.com/intrepretable-machine-learning-nfl-combine.html#Joint-Feature-Contributions 这个漂亮的文档来研究联合特征贡献。但这仅适用于 RandomForest 算法,因为树解释器(不适用于 xgboost)。 XGBoost 是否也有类似的出路?

基本上我想要实现的是找出所有特征组合对预测的共同贡献。例如,如果我有 a、b 和 c 作为我的特征,我想知道 ab、bc 和 ca 对预测结果的影响。它与 shap 和 Lime 非常相似,但用于组合功能。

【问题讨论】:

  • 您尝试过使用 scikit learn api 吗? xgboost.readthedocs.io/en/latest/python/…
  • 您可以在这里提问:datascience.stackexchange.com 作为快速回答,并非所有机器学习算法都支持您正在寻找的内容...
  • 我查看了文档,但没有找到任何内容。
  • 我确实在 datascience,stackexchange.com 上发布了同样的问题。感谢您的建议!
  • @SudhakarSamak 抱歉,我帮不上忙,但如果/当您找到有效的解决方案时,我很感兴趣。请随时通知我们

标签: python machine-learning random-forest xgboost shap


【解决方案1】:

我做了一些研究并了解了 xgbfir 包。它将联合贡献输出到一个 excel 文件中。您可以设置与此交互的级别。我围绕它编写了一些代码来生成一个解决该目的的图。

如果没有安装包

pip install xgbfir

安装后:

import xgbfir
from matplotlib import pyplot as plt

xgbfir.saveXgbFI(model, feature_names=X.columns, OutputXlsxFile='FI.xlsx')

joint_contrib = pd.read_excel('FI.xlsx')

xls = pd.ExcelFile('FI.xlsx')
df1 = pd.read_excel(xls, 'Interaction Depth 0')
df2 = pd.read_excel(xls, 'Interaction Depth 1')
df3 = pd.read_excel(xls, 'Interaction Depth 2')

frames = [df1, df2, df3]
joint_contrib = pd.concat(frames)

joint_contrib=joint_contrib.sort_values(by='Gain', ascending=True)
joint_contrib=joint_contrib.head(20)

height = joint_contrib['Gain']
bars = joint_contrib['Interaction']
y_pos = np.arange(len(bars))

plt.barh(y_pos, height)
plt.yticks(y_pos, bars)
plt.show()

这将给出前 20 个功能交互的增益。

感谢 Philip Cho 将我介绍给 xgbfir。

点击链接了解更多关于xgbfir的信息

【讨论】:

    猜你喜欢
    • 2017-05-26
    • 2017-03-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多