【问题标题】:Glue and For to many models with Automl - R使用 Automl - R 对许多模型进行 Glue 和 For
【发布时间】:2020-01-22 09:35:12
【问题描述】:

我想重现这段代码:

X_train_model1 <- data.table::fread("datasets_atualizados/dataset_y1.csv") %>% 
  h2o::as.h2o()

X_train_model2<- data.table::fread("datasets_atualizados/dataset_y2.csv") %>% 
  h2o::as.h2o()

#Model construction (20 different models)
model_automl <- h2o.automl(x = 1:11, y = 12, training_frame = X_train_model1,
                max_models = 20, seed = 1)

# Save the model
# In this case the leaderboard model is StackedEnsemble_AllModels
model_path <- h2o.saveModel(object = model_automl@leader, path = "models", force=TRUE)

看起来像这样:

for (i in 1:2) {

  #Exec the model
  model_automl <- h2o.automl(x = 1:11, y = 12, training_frame = glue::glue("X_train_model", {i}),
                               max_models = 20, seed = 1)
  #Saving the model
  h2o.saveModel(object = model_automl@leader, 
                path = paste0("models", i),
                force=TRUE)
}

我真诚地已经尝试过不同的形式,但我不总结这段代码。 你能帮帮我吗?

【问题讨论】:

    标签: r for-loop automl r-glue


    【解决方案1】:

    我认为{i} 在您的代码中的位置错误,应该在字符串内:

    for (i in 1:2) {
    
      #Exec the model
      model_automl <- h2o.automl(
        x = 1:11, 
        y = 12, 
        training_frame = get(glue::glue("X_train_modelo{i}")),
        max_models = 20, 
        seed = 1
      )
    
      #Saving the model
      h2o.saveModel(object = model_automl@leader, 
                    path = paste0("models", i),
                    force=TRUE)
    }
    

    我了解到您有多个 X_train_modelo 对象,因此您需要使用 get() 来按名称引用它们。

    【讨论】:

    • 是的,它们是多个模型。我做了替换,但它仍然不起作用。
    猜你喜欢
    • 1970-01-01
    • 2020-03-23
    • 2014-01-24
    • 1970-01-01
    • 2020-05-30
    • 2020-11-20
    • 2019-06-21
    • 2023-03-08
    • 1970-01-01
    相关资源
    最近更新 更多