Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ensure that arguments haven't been mistakenly registered as model arguments #1052

Closed
simonpcouch opened this issue Jan 16, 2024 · 2 comments · Fixed by #1054
Closed

ensure that arguments haven't been mistakenly registered as model arguments #1052

simonpcouch opened this issue Jan 16, 2024 · 2 comments · Fixed by #1054

Comments

@simonpcouch
Copy link
Contributor

If an engine argument has been mistakenly registered as a model argument for a given engine, that argument becomes protected. e.g. #1051--let's write up a quick check to make sure this hasn't happened elsewhere.

@simonpcouch
Copy link
Contributor Author

simonpcouch commented Jan 18, 2024

Turns out there are a good few arguments that match this description:

With pak::pak("tidymodels/parsnip") and then pak::pak(paste0("tidymodels/", parsnip:::extensions())):

library(tidymodels)
library(rlang)

exts <- map_lgl(parsnip:::extensions(), require, character.only = TRUE)
all(exts)
#> [1] TRUE

m_env <- get_model_env()

# get all model types, e.g. "linear_reg"
models <- env_get(m_env, "models")

# their argument info is in "model_type_args"
models_args <- paste0(models, "_args")

# find the actual argument names
args_actual <- map(models, ~names((formals(.x))))
args_actual <- map(args_actual, ~.x[!.x %in% c("mode", "engine")])

# gather the registered model arguments
args_registered <- map(models_args, env_get, env = m_env)

# keep only arguments that are registered but are not actual model arguments
args_misregistered <- map2(args_registered, args_actual, ~filter(.x, !parsnip %in% .y))
args_misregistered <- map2(args_misregistered, models, ~mutate(.x, model_type = .y))

bind_rows(args_misregistered) %>% select(engine, argument = parsnip, model_type)
#> # A tibble: 16 × 3
#>    engine   argument   model_type   
#>    <chr>    <chr>      <chr>        
#>  1 partykit mtry       decision_tree
#>  2 brulee   epochs     linear_reg   
#>  3 brulee   learn_rate linear_reg   
#>  4 brulee   momentum   linear_reg   
#>  5 brulee   stop_iter  linear_reg   
#>  6 brulee   epochs     logistic_reg 
#>  7 brulee   learn_rate logistic_reg 
#>  8 brulee   momentum   logistic_reg 
#>  9 brulee   stop_iter  logistic_reg 
#> 10 brulee   mixture    mlp          
#> 11 brulee   momentum   mlp          
#> 12 brulee   epochs     multinom_reg 
#> 13 brulee   learn_rate multinom_reg 
#> 14 brulee   momentum   multinom_reg 
#> 15 brulee   stop_iter  multinom_reg 
#> 16 partykit tree_depth rand_forest

Created on 2024-01-18 with reprex v2.1.0

Copy link

github-actions bot commented Feb 8, 2024

This issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with a reprex: https://reprex.tidyverse.org) and link to this issue.

@github-actions github-actions bot locked and limited conversation to collaborators Feb 8, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant