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

Add support for updating recipe/model in workflowset object #64

Closed
3 tasks
juliasilge opened this issue Dec 9, 2021 · 3 comments · Fixed by #65
Closed
3 tasks

Add support for updating recipe/model in workflowset object #64

juliasilge opened this issue Dec 9, 2021 · 3 comments · Fixed by #65
Labels
feature a feature request or enhancement

Comments

@juliasilge
Copy link
Member

We would like to support the functionality of update_recipe() and update_model() for the workflowset object, so for example someone can use a sparse blueprint or a special model formula.

I do find it worrisome that this currently runs without error, even though it is not doing anything with sparse_bp:

library(tidymodels)
#> Registered S3 method overwritten by 'tune':
#>   method                   from   
#>   required_pkgs.model_spec parsnip

data(parabolic)
set.seed(1)
split <- initial_split(parabolic)
train_set <- training(split)
test_set <- testing(split)
set.seed(2)
train_resamples <- bootstraps(train_set)


glmnet_spec <- 
  logistic_reg(penalty = 0.1, mixture = 0) %>%
  set_engine("glmnet")

rec <-
  recipe(class ~ ., data = train_set) %>%
  step_YeoJohnson(all_numeric_predictors())

sparse_bp <- hardhat::default_recipe_blueprint(composition = "dgCMatrix")

workflow_set(
  preproc = list(yj = rec, 
                 norm = rec %>% step_normalize(all_numeric_predictors())),
  models = list(regularized = glmnet_spec)
) %>%
  option_add(blueprint = sparse_bp) %>%
  workflow_map(fn = "fit_resamples", resamples = train_resamples)
#> # A workflow set/tibble: 2 × 4
#>   wflow_id         info             option    result   
#>   <chr>            <list>           <list>    <list>   
#> 1 yj_regularized   <tibble [1 × 4]> <opts[2]> <rsmp[+]>
#> 2 norm_regularized <tibble [1 × 4]> <opts[2]> <rsmp[+]>

Created on 2021-12-09 by the reprex package (v2.0.1)

IMO there are three things to address:

  • support the update_recipe() / update_model() functionality
  • possibly error or warn if something is passed to option_add() that does nothing?
  • document (if it is already here) or create a way to get at the fitted workflow result, so I could for example call extract_mold() and see what happened during fitting (maybe just the extract arg of the control object?)
@juliasilge juliasilge added the feature a feature request or enhancement label Dec 9, 2021
@topepo
Copy link
Member

topepo commented Dec 10, 2021

Do either of these patterns seem preferable to you or @DavisVaughan?

# ------------------------------------------------------------------------------
# option 1

update_workflow <-
  function(x, id, recipe = NULL,  blueprint = NULL, spec = NULL, formula = NULL) {
    
    wflow <- extract_workflow(x, id = id)
    
    # update_recipe and/or update_model
    
    # stuff back into workflow set
    
  }

# ------------------------------------------------------------------------------
# option 2

update_workflow_model <- function(x, id, spec, formula = NULL) {
    # stuff
}

update_workflow_recipe <- function(x, id, recipe, blueprint = NULL) {
  # stuff
}

@juliasilge
Copy link
Member Author

I think I prefer option 2 but that is a weakly held opinion.

@github-actions
Copy link

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 Mar 29, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature a feature request or enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants