tidymodels / workflowsets

Create a collection of modeling workflows
https://workflowsets.tidymodels.org/
Other
92 stars 10 forks source link

collect_extracts() for workflow_set #156

Closed jrosell closed 2 months ago

jrosell commented 5 months ago

I noticed that workflowsets do not appear to have a method for collecting extracts and it have a method for collecting notes https://github.com/tidymodels/workflowsets/issues/135.

class(results) [1] "workflow_set" "tbl_df" "tbl" "data.frame" collect_extracts(results) Error in collect_extracts(): ! No collect_extracts() exists for a <workflow_set/tbl_df/tbl/data.frame> object. Run rlang::last_trace() to see where the error occurred.

It would be handy to have collect_extracts implemented so that you can get elapsed time or other information extracted.

Here one example using partials if you want to reuse the code for mulitple collect_*

my_collect_custom <- function(wflow_set_results, fn){
  wflow_set_rsl <- wflow_set_results %>%
    dplyr::select(wflow_id, result)

  distinct_list_of_workflows <- wflow_set_rsl %>%
    dplyr::select(wflow_id) %>%
    distinct() %>%
    pull(wflow_id)

  collect_fn_helper <- function(x){
    wflow_set_rsl %>%
          filter(wflow_id == x) %>%
          pull(result) %>%
          pluck(1) %>%
          fn()
  }
  list_dfs <- map_dfr(
    set_names(distinct_list_of_workflows),
    collect_fn_helper,
    .id = "workflow_id")

  list_dfs
}

my_collect_extracts <- purrr::partial(my_collect_custom, fn = collect_extracts)
my_collect_extracts(results)

my_collect_notes <- purrr::partial(my_collect_custom, fn = collect_notes)
my_collect_notes(results)
simonpcouch commented 5 months ago

Yup, totally on board. Thanks for the issue. Will try to carve out time for this next time I'm focused on workflowsets!

jrosell commented 3 months ago

Could I help with a PR or do you have some refactoring in mind?

simonpcouch commented 3 months ago

I'm not focused on the package at the moment and will revisit once I sit down with the package for a day or two, but you're welcome to give the PR a go in the meantime!

jrosell commented 2 months ago

Closed by https://github.com/tidymodels/workflowsets/pull/161