【发布时间】:2018-05-28 19:13:51
【问题描述】:
我是 python 中的 H2O 新手。我正在尝试按照 H2O 网站上的示例代码使用集成模型对我的数据进行建模。 (http://docs.h2o.ai/h2o/latest-stable/h2o-docs/data-science/stacked-ensembles.html)
我已应用 GBM 和 RF 作为基本模型。然后使用堆叠,我尝试将它们合并到集成模型中。此外,在我的训练数据中,我创建了一个名为“fold”的附加列,用于fold_column = "fold"
我申请了 10 倍的 cv,我观察到我收到了来自 cv1 的结果。然而,来自其他 9 个 cv 的所有预测都是空的。我在这里错过了什么?
这是我的示例数据:
代码:
import h2o
from h2o.estimators.random_forest import H2ORandomForestEstimator
from h2o.estimators.gbm import H2OGradientBoostingEstimator
from h2o.estimators.stackedensemble import H2OStackedEnsembleEstimator
from h2o.grid.grid_search import H2OGridSearch
from __future__ import print_function
h2o.init(port=23, nthreads=6)
train = h2o.H2OFrame(ens_df)
test = h2o.H2OFrame(test_ens_eq)
x = train.drop(['Date','EQUITY','fold'],axis=1).columns
y = 'EQUITY'
cat_cols = ['A','B','C','D']
train[cat_cols] = train[cat_cols].asfactor()
test[cat_cols] = test[cat_cols].asfactor()
my_gbm = H2OGradientBoostingEstimator(distribution="gaussian",
ntrees=10,
max_depth=3,
min_rows=2,
learn_rate=0.2,
keep_cross_validation_predictions=True,
seed=1)
my_gbm.train(x=x, y=y, training_frame=train, fold_column = "fold")
然后当我用
检查简历结果时my_gbm.cross_validation_predictions():
另外,当我在测试集中尝试集成时,我收到以下警告:
# Train a stacked ensemble using the GBM and GLM above
ensemble = H2OStackedEnsembleEstimator(model_id="mlee_ensemble",
base_models=[my_gbm, my_rf])
ensemble.train(x=x, y=y, training_frame=train)
# Eval ensemble performance on the test data
perf_stack_test = ensemble.model_performance(test)
pred = ensemble.predict(test)
pred
/mgmt/data/conda/envs/python3.6_4.4/lib/python3.6/site-packages/h2o/job.py:69: UserWarning: Test/Validation dataset is missing column 'fold': substituting in a column of NaN
warnings.warn(w)
我是否遗漏了有关 fold_column 的内容?
【问题讨论】:
-
您能否修改您的示例以使其使用公开可用的数据集? stackoverflow.com/help/mcve 另外请说明您是如何检查 CV preds 的(这里没有显示您在做什么的代码)。
-
@ErinLeDell 我把与 CV preds 相关的行。此外,虽然我将创建一个示例数据集,但我有一个小问题。我注意到在示例代码中,它使用
cars.kfold_column(n_folds = 5, seed = 1234)为 fold_column 分配随机数。我不想分配随机数,而是想为 fold_column 使用数据(列表等)。例如。我试过train['fold'].kfold_column(),但它仍然分配随机数。如何将数据引入 kfold_column?或者在不使用kfold_column的情况下,只在训练集中有一个“折叠”列就足够了?
标签: python-3.x h2o ensemble-learning