1

I want to reproduce this code:

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)

Look like this:

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)
}

I sincerely already tried different forms, but I don't conclude this code. Can you help me?

4

1 回答 1

0

我认为{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()名称来引用它们。

于 2019-09-21T21:12:33.253 回答