Is this a bug in tidy models?

I’m trying to tune the degrees of freedom in a spline recipe using tidymodels (tune and dials). I get an error message about a type mismatch between the range and the parameter.

This is the basic tuning I was attempting:

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.

Created on 2023-03-02 with reprex v2.0.2

I can tune deg_free using tune() but seem to get the error regardless of what range I specify for degree. I tried using degree and spline_degree (which is an integer).

Is this a bug? If so, which package should I file against?

>Solution :

This appears to be a bug in {recipes}. I have opened a PR with a fix https://github.com/tidymodels/recipes/pull/1100.

If this is a blocker for you, you can install that specific branch with remotes::install_github("tidymodels/recipes#1100").

Using that PR, you get the following results

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.

Leave a Reply