我正在尝试将h2o.automl
中的所有模型保存为h2o
软件包的一部分。目前,我可以使用h2o.saveModel(aml@leader, path = "/home/data/user")
保存一个模型。
如何保存所有模型?
这是我对样本数据集的尝试:
library(h2o)
h2o.init()
prostate.hex <- h2o.importFile(path = paste("https://raw.github.com",
"h2oai/h2o-2/master/smalldata/logreg/prostate.csv", sep = "/"),
destination_frame = "prostate.hex")
从github获取数据或通过readr
导入:
library(readr)
prostate <- read_csv("/home/data/user/prostate.csv")
prostate.hex<- as.h2o(prostate, "prostate.hex")
aml <- h2o.automl(y = "CAPSULE", x = c("AGE","RACE","PSA","DCAPS"),
training_frame = prostate.hex,
max_runtime_secs = 180,
exclude_algos = c("StackedEnsemble")
)
现在我正在尝试在aml
中保存模型:
mod_ids <- as_tibble(aml@leaderboard$model_id)
现在我不知道如何保存模型:
for(i in 1:nrow(mod_ids)) {
print(mod_ids[i,])
#h2o.saveModel(object = aml@leaderboard[[i]], "/home/data/user/")
}
这是我尝试过的:
H2O AUTOML: How to save reuse and build on top of existing automl models
答案 0 :(得分:3)
尝试一下,它会完成您的工作:
for(i in 1:nrow(mod_ids)) {
aml1 <- h2o.getModel(aml@leaderboard[i, 1]) # get model object in environment
h2o.saveModel(object = aml1, "C:/Users/sm/Documents/stack/models") # pass that model object to h2o.saveModel as an argument
}