我找到了答案。
我用H2o库运行我的模型。我用5倍交叉验证运行。
model = H2OGradientBoostingEstimator(
balance_classes=True,
nfolds=5,
keep_cross_validation_fold_assignment=True,
seed=1234)
model.train(x=predictors,y=response,training_frame=data)
print('rmse: ',model.rmse(xval=True))
print('R2: ',model.r2(xval=True))
data_nfolds = model.cross_validation_fold_assignment()
我得到了交叉验证的任务。我试图将它重新用于具有其他参数(如ntrees或stopping_rounds(的新模型,但在文档中找不到它。
https://docs.h2o.ai/h2o/latest-stable/h2o-docs/data-science/algo-params/keep_cross_validation_fold_assignment.html
nfolds_index = h2o.import_file('myfile_index.csv')
nfolds_index.set_names(["fold_numbers"])
data = data.cbind(nfolds_index)
model2 = H2OGradientBoostingEstimator( seed=1234)
model2.train(x=predictors,y=response,training_frame=data, fold_column="fold_numbers")
print('rmse: ',model2.rmse(xval=True))
print('R2: ',model2.r2(xval=True))