xgboost预测对概率的贡献

时间:2019-03-08 16:25:02

标签: python machine-learning data-science xgboost

我正在使用xgboost的功能pred_contribs,以便为模型的每个样本获得某种可解释性(shapley值)。

booster.predict(test, pred_contribs=True)

它返回形状(样本数)x(特征数)的贡献向量。捐款总和等于保证金得分。

但是,我想使用概率而不是保证金得分,并且为了简单起见,我想转换(近似)贡献概率。

有办法吗?

代码示例:

from sklearn.datasets import make_classification
from sklearn.model_selection import train_test_split
import xgboost as xgb

X, y = make_classification()
X_train, X_test, y_train, y_test = train_test_split(X, y)

dtrain = xgb.DMatrix(X_train, label=y_train)
dtest = xgb.DMatrix(X_test, label=y_test)

param = {
    'max_depth': 2,
    'eta': 1,
    'silent': 1,
    'objective': 'binary:logistic',
    'eval_metric': 'auc'
}

booster = xgb.train(param, dtrain, 50)

probabilites = booster.predict(dtest)

margin_score = booster.predict(dtest, output_margin=True)

contributions = booster.predict(dtest, pred_contribs=True)

0 个答案:

没有答案