H2o Python:结合 XGB 阻止预测

H2o Python: Combining XGB Holdout Predictions

使用时:

"keep_cross_validation_predictions": True
"keep_cross_validation_fold_assignment": True

在 H2O 的 XGBoost 估计器中,我无法将这些经过交叉验证的概率映射回原始数据集。 R 有一个文档示例,但 Python 没有(结合坚持预测)。

在 Python 中有关于如何做到这一点的线索吗?

对于Python有an example of this on GBM,对于XGB应该是完全一样的。根据该页面,您应该可以执行以下操作:

model = H2OXGBoostEstimator(keep_cross_validation_predictions = True)

model.train(x = predictors, y = response, training_frame = train)

cv_predictions = model.cross_validation_predictions()

交叉验证的预测存储在两个不同的地方——一个是 model.cross_validation_predictions() 中长度为 k 的列表(对于 k 折叠),另一个是 H2O 框架,其中 CV 预测在与 model.cross_validation_holdout_predictions() 中原始训练行的顺序相同。后者通常是人们想要的(我们后来添加了这个,这就是为什么有两个版本)。

是的,不幸的是 R example to get this frame in the "Cross-validation" section of the H2O User Guide does not have a Python version (ticket to fix that). In the keep_cross_validation_predictions 参数文档,它只显示了两个位置之一。

这是一个使用 XGBoost 并显示两种类型的 CV 预测的更新示例:

import h2o
from h2o.estimators.xgboost import H2OXGBoostEstimator
h2o.init()

# Import a sample binary outcome training set into H2O
train = h2o.import_file("http://s3.amazonaws.com/erin-data/higgs/higgs_train_10k.csv")

# Identify predictors and response
x = train.columns
y = "response"
x.remove(y)

# For binary classification, response should be a factor
train[y] = train[y].asfactor()

# try using the `keep_cross_validation_predictions` (boolean parameter):
# first initialize your estimator, set nfolds parameter
xgb = H2OXGBoostEstimator(keep_cross_validation_predictions = True, nfolds = 5, seed = 1)

# then train your model
xgb.train(x = x, y = y, training_frame = train)

# print the cross-validation predictions as a list
xgb.cross_validation_predictions()

# print the cross-validation predictions as an H2OFrame
xgb.cross_validation_holdout_predictions()

预测的 CV 预测框架如下所示:

Out[57]:
  predict         p0        p1
---------  ---------  --------
        1  0.396057   0.603943
        1  0.149905   0.850095
        1  0.0407018  0.959298
        1  0.140991   0.859009
        0  0.67361    0.32639
        0  0.865698   0.134302
        1  0.12927    0.87073
        1  0.0549603  0.94504
        1  0.162544   0.837456
        1  0.105603   0.894397

[10000 rows x 3 columns]