【问题标题】:Error message: All models failed in tune_grid(). See the `.notes` column. When tuning parameters for random forest model错误消息:所有模型在 tune_grid() 中均失败。请参阅 `.notes` 列。调整随机森林模型的参数时
【发布时间】:2021-02-17 12:46:11
【问题描述】:
bos <- read_csv("boston_train.csv") %>% clean_names()

bos %>%
  mutate_if(is.character, factor) -> bos

然后我拆分数据并进行 k 折叠

# -- set a random seed for repeatablity 
set.seed(42)

# -- performs our train / test split 
split <- initial_split(bos, prop = 0.7)

# -- extract the training data form our bananna split 
train <- training(split)
# -- extract the test data 
test <- testing(split)

tree_fold <- vfold_cv(train, 10)

sprintf("Train PCT : %1.2f%%", nrow(train)/ nrow(bos) * 100)
sprintf("Test  PCT : %1.2f%%", nrow(test)/ nrow(bos) * 100)

我的目标变量是一个连续变量,我需要我的随机森林来解决回归问题

# recipe 
rf_recipe <- recipe(av_total ~ ., data=train) %>%
  step_rm(pid, zipcode) %>%
  step_meanimpute(all_numeric(), -all_outcomes()) %>%
  step_log(all_numeric()) %>%
  step_modeimpute(all_nominal(),-all_outcomes()) %>%
  step_dummy(all_nominal(), -all_outcomes())

#tuning parameters
rf_model <- rand_forest(
  mtry = tune(),
  trees = 10,
  min_n= tune()
  ) %>%
  set_engine("ranger",
             importance = "permutation") %>%
  set_mode("regression")

rf_wf <- workflow() %>%
  add_recipe(rf_recipe) %>%
  add_model(rf_model)

rf_grid <- grid_random(mtry(c(5,7)),
                       min_n(c(15,20)),
                       size = 10)
# do parallel
all_cores <- detectCores(logical = TRUE)
sprintf("# of Logical Cores: %d", all_cores)
cl <- makeCluster(all_cores)
registerDoParallel(cl)

然后我遇到了错误,无论我如何更改配方或调整过程,它仍然存在

set.seed(52)
rf_tune_rs <- rf_wf %>%
  tune_grid(
  resamples = tree_fold,
  grid = rf_grid,
  control = control_resamples(save_pred = TRUE)
)

【问题讨论】:

    标签: r machine-learning parameters random-forest tidymodels


    【解决方案1】:

    我通过在我的食谱中添加 step_unknown 术语来修复它

    【讨论】:

    • 你能具体点吗?您是如何添加“step_unknown”术语的?
    猜你喜欢
    • 2013-07-23
    • 2019-05-01
    • 2021-02-05
    • 2016-01-24
    • 2020-02-25
    • 2017-10-20
    • 2018-06-05
    • 2019-07-10
    • 2017-08-11
    相关资源
    最近更新 更多