首页 > 解决方案 > 使用 tidymodels 未检测到调整参数

问题描述

直到最后更新以下代码有效:

model_recipe_prep <- recipe( leads_dda ~ ., data = train_data) %>%
  step_rm(dt,cost) %>% 
  step_normalize( all_numeric(), -all_outcomes() ) %>% 
  step_BoxCox( all_numeric(), -all_outcomes(), -starts_with("number_")) %>%
  step_dummy( all_nominal(), one_hot = TRUE) %>% 
  step_poly(impressions, degree = tune() ) %>% 
  step_nzv(all_predictors() ) 

# ---- Metrics ----
model_control_metrics <- metric_set( rmse, mae, rsq )
model_control         <- control_grid(save_pred = TRUE)

model_baseline <- linear_reg() %>% 
  set_engine("lm") %>% 
  set_mode("regression")

set.seed(3456)
model_baseline_recipe_grid  <- expand.grid(degree = 1:3)
#model_baseline_engine_grid <- grid_regular()
#model_baseline_grid        <- merge(model_recipe_base_linear, model_baseline_engine_grid)

model_baseline_tune <- tune_grid(
  model_baseline,
  model_recipe_prep,
  resamples = train_data_kfolds,
  grid = model_baseline_recipe_grid,
  control = model_control,
  metrics = model_control_metrics
)

但现在我开始收到如下错误:

警告消息:1:未检测到调整参数,将使用未调整的重新采样评估性能。你想要 [fit_resamples()] 吗?2:所有模型在 tune_grid() 中均失败。见.notes专栏。

在 .notes 字段中,我有类似的内容:

“配方:错误:您无法prep()调整配方。参数带有tune():'degree'。您想使用调整功能吗?例如 tune_grid()

也许我错过了一些非常愚蠢的东西,但我不知道如何让它再次工作。

另外,如果我检查

tune_args(model_recipe_prep)

因为 model_recipe_prep 没有可靠的参数,所以我有一个空的半字节。

标签: rtidyversetidymodels

解决方案


不幸的是,我们了解到,在某些情况下,刚刚进入 CRAN 的新版本食谱与 CRAN 上的当前调整版本之间可能存在不匹配。我们正在尽快发布调整版本,但与此同时,如果您能够通过 GitHub 进行安装devtools::install_github("tidymodels/tune"),应该可以解决您的问题,您应该会看到如下内容:

library(tidymodels)

rec1 <- recipe( mpg ~ ., data = mtcars) %>%
    step_normalize( all_numeric(), -all_outcomes() ) %>% 
    step_BoxCox( all_numeric(), -all_outcomes(), -starts_with("number_")) %>%
    step_dummy( all_nominal(), one_hot = TRUE) %>% 
    step_poly(disp, degree = tune() ) %>% 
    step_nzv(all_predictors() ) 

tunable(rec1)
#> # A tibble: 3 x 5
#>   name       call_info        source component component_id
#>   <chr>      <list>           <chr>  <chr>     <chr>       
#> 1 degree     <named list [2]> recipe step_poly poly_Dj0QK  
#> 2 freq_cut   <named list [2]> recipe step_nzv  nzv_zIzsm   
#> 3 unique_cut <named list [2]> recipe step_nzv  nzv_zIzsm
tune_args(rec1)
#> # A tibble: 1 x 6
#>   name   tunable id     source component component_id
#>   <chr>  <lgl>   <chr>  <chr>  <chr>     <chr>       
#> 1 degree TRUE    degree recipe step_poly poly_Dj0QK

reprex 包(v0.3.0.9001)于 2020 年 11 月 15 日创建


推荐阅读