Extract the parameters of a tidyflow

parameters(x, ...)

Arguments

x

A tidyflow

...

Not used.

Value

A tibble of class parameters

Details

parameters extracts the tune parameters from both the model and recipe. In principle, the user never should need to extract them. Behind the scenes, tidyflow extracts them and generates random values based on the defaults by link[dials]{dials}. However, the user might want to extract the parameters to figure out which parameters were correctly supplied to the tidyflow.

This function can be used on the tidyflow both before fitting the model and after the model fit.

Examples

library(rsample)
library(tune)
#> 
#> Attaching package: ‘tune’
#> The following object is masked from ‘package:tidyflow’:
#> 
#>     parameters
library(dials)
#> Loading required package: scales
#> 
#> Attaching package: ‘dials’
#> The following object is masked from ‘package:tidyflow’:
#> 
#>     parameters
library(recipes)
#> Loading required package: dplyr
#> 
#> Attaching package: ‘dplyr’
#> The following objects are masked from ‘package:stats’:
#> 
#>     filter, lag
#> The following objects are masked from ‘package:base’:
#> 
#>     intersect, setdiff, setequal, union
#> 
#> Attaching package: ‘recipes’
#> The following object is masked from ‘package:stats’:
#> 
#>     step
library(parsnip)

tflow <-
  mtcars %>%
  tidyflow() %>%
  plug_split(initial_split) %>%
  plug_formula(mpg ~ .) %>% 
  plug_resample(vfold_cv) %>%
  plug_grid(grid_regular) %>%
  plug_model(set_engine(linear_reg(), "lm"))

# No tuning parameters
tidyflow::parameters(tflow)
#> Collection of 0 parameters for tuning
#> 
#> [1] identifier type       object    
#> <0 rows> (or 0-length row.names)
#> 

# But if we add tuning parameters, we can check which ones:
tflow %>%
  drop_formula() %>% 
  plug_recipe(~ recipe(mpg ~ ., data = .) %>% step_ns(hp, deg_free = tune())) %>%
  tidyflow::parameters()
#> Collection of 0 parameters for tuning
#> 
#> [1] identifier type       object    
#> <0 rows> (or 0-length row.names)
#> 

# parameters extracts both the tuning parameters from the recipe and
# model:
tflow <-
  tflow %>%
  drop_formula() %>% 
  plug_recipe(~ recipe(mpg ~ ., data = .) %>% step_ns(hp, deg_free = tune())) %>%
  replace_model(set_engine(linear_reg(penalty = tune(), mixture = tune()), "glmnet"))

tidyflow::parameters(tflow)
#> Collection of 2 parameters for tuning
#> 
#>  identifier    type    object
#>     penalty penalty nparam[+]
#>     mixture mixture nparam[+]
#> 

# This can serve well to refresh your memory on which tuning
# parameters are present and then override the custom values
# in `plug_grid`:
if (FALSE) {
  res <-
    tflow %>%
    replace_grid(grid_regular, penalty = penalty(c(-1, 0))) %>%
    fit()
  res
}