H2O 堆叠集成与使用不同输入的模型

H2O stacked ensemble with models using different inputs

使用 h2o flow,有没有一种方法可以创建基于单个模型的堆叠集成模型,这些模型可能不采用相同的输入但在相同的响应标签上进行预测。

例如。我正在尝试预测错误编码的医疗保健索赔(即收费),并想为以下形式的堆叠集合训练模型:

model1(diagnosis1, diagnosis2, ..., diagnosis5) -> denied or paid (by insurer)
model2(procedure, procedure_detail1, ..., procedure_detail5) -> denied or paid 
model3(service_date, insurance_amount, insurer_id) -> (same)
model4(pat_age, pat_sex, ...) -> (same)
...

有没有办法在 h2o flow 中执行此操作(无法说明如何使用 h2o flow 堆叠合奏的 gui 中显示的内容执行此操作)?这甚至是解决此问题的明智方法还是在某种程度上令人困惑(对机器学习来说相对较新)?谢谢

堆叠式集成不会执行此操作,因为它确实需要对每个模型进行相同的输入。但是你可以建立一个更宽松的整体......这几乎可以但不完全可以在 Flow 中完成。

基本上,您将创建四个模型。然后你会 运行 对它们中的每一个进行预测。每个 predict() 都会给你一个新的 h2o 框架。然后,您需要将这四个预测 cbind(列绑定)在一起,为您提供一个包含 4 个二进制列 (*) 的新 h2o 框架。然后将其输入到第 5 个模型中,为您提供综合结果。

*:这是我认为您无法在 Flow 中做到的一点。您需要导出数据,将其合并到另一个应用程序中,然后再将其导入。

更好的方法是使用所有输入一起构建一个模型。这会更简单,并为您提供更准确的结果(例如,可以发现 insurance_amount 和 pat_age 之间的相互作用)。但是,(可能是主要的)缺点是您不能再将模型解释为四组 yes/no。 IE。它变得更像黑盒。

Darren 的回答是你不能在 H2O 中做到这一点 直到最近才 是正确的 -- H2O 只是 removed the requirement that the base models had to be trained on the same set of inputs since it's not actually required by the Stacked Ensemble algorithm. This is only available on the nightly releases 离开 master,所以即使你'在最新的稳定版本上,如果您尝试使用不使用完全相同列的模型,您会看到如下所示的错误(在 Flow、R、Python 等中):

Error: water.exceptions.H2OIllegalArgumentException: Base models are inconsistent: they use different column lists.  Found: [x6, x7, x4, x5, x2, x3, x1, x9, x8, x10, response] and: [x10, x16, x15, x18, x17, x12, x11, x14, x13, x19, x9, x8, x20, x21, x28, x27, x26, x25, x24, x23, x22, x6, x7, x4, x5, x2, x3, x1, response].  

Stacked Ensemble 算法中的元学习步骤结合了基础模型的 输出 ,因此用于训练基础模型的输入数量并不重要。目前,H2O 仍然要求输入都是相同原始 training_frame 的一部分——但如果您愿意,您可以为每个基本模型使用不同的 xx 参数指定哪个您要在模型中使用的 training_frame 中的列数)。

Stacked Ensemble 在 Flow 中的工作方式是它寻找所有 "compatible" 的模型,换句话说——在相同的数据帧上训练。然后你 select 从这个列表中选择你想要包含在整体中的那些。所以只要你使用的是最新开发版的H2O,那么这就是你想在Flow中做的事情。

这是一个 R 示例,说明如何集成在特征的不同子集上训练的模型 space:

library(h2o)
h2o.init()

# Import a sample binary outcome training set into H2O
train <- h2o.importFile("https://s3.amazonaws.com/erin-data/higgs/higgs_train_10k.csv")
test <- h2o.importFile("https://s3.amazonaws.com/erin-data/higgs/higgs_test_5k.csv")

# Identify predictors and response
y <- "response"
x <- setdiff(names(train), y)

# For binary classification, response should be a factor
train[,y] <- as.factor(train[,y])
test[,y] <- as.factor(test[,y])

# Train & Cross-validate a GBM using a subset of features
my_gbm <- h2o.gbm(x = x[1:10],
                  y = y,
                  training_frame = train,
                  distribution = "bernoulli",
                  nfolds = 5,
                  keep_cross_validation_predictions = TRUE,
                  seed = 1)

# Train & Cross-validate a RF using a subset of features
my_rf <- h2o.randomForest(x = x[3:15],
                          y = y,
                          training_frame = train,
                          nfolds = 5,
                          keep_cross_validation_predictions = TRUE,
                          seed = 1)

# Train a stacked ensemble using the GBM and RF above
ensemble <- h2o.stackedEnsemble(y = y, training_frame = train,
                                base_models = list(my_gbm, my_rf))

# Check out ensemble performance
perf <- h2o.performance(ensemble, newdata = test)
h2o.auc(perf)