如何从H2O AUTOML保存所有模型

时间:2018-09-12 15:34:33

标签: r h2o

我正在尝试将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/")
 }

这是我尝试过的:

tutorial automl

H2O AUTOML: How to save reuse and build on top of existing automl models

1 个答案:

答案 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

  }