R语言 这是整洁模型中的缺陷吗?

ltqd579y  于 2023-03-10  发布在  其他
关注(0)|答案(1)|浏览(184)

我尝试使用tidymodels(tune和dial)调整样条配方中的自由度,但收到一条错误消息,提示范围和参数类型不匹配。
这是我尝试的基本调优:

library(tidymodels)

rec <- recipe(mpg ~ disp, data = mtcars) |>
  step_spline_b(disp, degree = tune())

rs <- vfold_cv(mtcars) 

workflow() |>
  add_recipe(rec) |>
  add_model(linear_reg()) |>
  tune_grid(resamples=rs)
#> Error in `mutate()`:
#> ℹ In argument: `object = purrr::map(call_info, eval_call_info)`.
#> Caused by error in `purrr::map()`:
#> ℹ In index: 1.
#> Caused by error in `.f()`:
#> ! Error when calling degree(): Error in new_quant_param(type = "double", range = range, inclusive = c(TRUE,  : 
#>   Since `type = 'double'`, please use that data type for the range.

创建于2023年3月2日,使用reprex v2.0.2
我可以使用tune()调优deg_free,但无论我为degree指定什么范围,似乎都会得到错误。我尝试使用degreespline_degree(这是一个整数)。
这是一个bug吗?如果是,我应该针对哪个包提交?

m1m5dgzv

m1m5dgzv1#

这似乎是{recipes}中的一个错误。我已经打开了一个带有修复https://github.com/tidymodels/recipes/pull/1100的PR。
如果这对您来说是一个障碍,您可以使用remotes::install_github("tidymodels/recipes#1100")安装该特定分支。
使用该PR,您将得到以下结果

library(tidymodels)

rec <- recipe(mpg ~ disp, data = mtcars) |>
  step_spline_b(disp, degree = tune())

rs <- vfold_cv(mtcars) 

workflow() |>
  add_recipe(rec) |>
  add_model(linear_reg()) |>
  tune_grid(resamples=rs)
#> → A | warning: Some 'x' values beyond boundary knots may cause ill-conditioned basis
#>                functions.
#> There were issues with some computations   A: x1
#> There were issues with some computations   A: x5
#> There were issues with some computations   A: x8
#> 
#> # Tuning results
#> # 10-fold cross-validation 
#> # A tibble: 10 × 4
#>    splits         id     .metrics         .notes          
#>    <list>         <chr>  <list>           <list>          
#>  1 <split [28/4]> Fold01 <tibble [8 × 5]> <tibble [0 × 3]>
#>  2 <split [28/4]> Fold02 <tibble [8 × 5]> <tibble [0 × 3]>
#>  3 <split [29/3]> Fold03 <tibble [8 × 5]> <tibble [4 × 3]>
#>  4 <split [29/3]> Fold04 <tibble [8 × 5]> <tibble [0 × 3]>
#>  5 <split [29/3]> Fold05 <tibble [8 × 5]> <tibble [0 × 3]>
#>  6 <split [29/3]> Fold06 <tibble [8 × 5]> <tibble [0 × 3]>
#>  7 <split [29/3]> Fold07 <tibble [8 × 5]> <tibble [0 × 3]>
#>  8 <split [29/3]> Fold08 <tibble [8 × 5]> <tibble [0 × 3]>
#>  9 <split [29/3]> Fold09 <tibble [8 × 5]> <tibble [4 × 3]>
#> 10 <split [29/3]> Fold10 <tibble [8 × 5]> <tibble [0 × 3]>
#> 
#> There were issues with some computations:
#> 
#>   - Warning(s) x8: Some 'x' values beyond boundary knots may cause ill-conditioned b...
#> 
#> Run `show_notes(.Last.tune.result)` for more information.

相关问题