tidyclust icon indicating copy to clipboard operation
tidyclust copied to clipboard

Find a way to have `finalize_workflow()` be more generic

Open EmilHvitfeldt opened this issue 3 years ago • 2 comments
trafficstars

This change might have to happen in workflows

library(tidymodels)
library(celery)
#> 
#> Attaching package: 'celery'
#> The following object is masked from 'package:parsnip':
#> 
#>     prepare_data

rec_spec <- recipe(~., data = mtcars)

kmeans_spec <- k_means(k = tune())

wf_spec <- workflow(rec_spec, kmeans_spec)

wf_spec %>% finalize_workflow(tibble(k = 3))
#> Error in `finalize_model()`:
#> ! `x` should be a parsnip model specification.

Created on 2022-05-12 by the reprex package (v2.0.1)

EmilHvitfeldt avatar May 13 '22 06:05 EmilHvitfeldt

This could be handled by setting letting finalize_model() be a generic. This way it is automatically handled in finalize_workflow()

EmilHvitfeldt avatar Jul 10 '22 21:07 EmilHvitfeldt

Note: We have tidyclust specific function finalize_workflow_tidyclust(). This should either be referenced in the tune function or we move over to use refactor it

library(tidymodels)
library(tidyclust)
#> 
#> Attaching package: 'tidyclust'
#> The following object is masked from 'package:parsnip':
#> 
#>     prepare_data

rec_spec <- recipe(~., data = mtcars)

kmeans_spec <- k_means(k = tune())

wf_spec <- workflow(rec_spec, kmeans_spec)

wf_spec %>% finalize_workflow_tidyclust(tibble(k = 3))
#> ══ Workflow ════════════════════════════════════════════════════════════════════
#> Preprocessor: Recipe
#> Model: k_means()
#> 
#> ── Preprocessor ────────────────────────────────────────────────────────────────
#> 0 Recipe Steps
#> 
#> ── Model ───────────────────────────────────────────────────────────────────────
#> K Means Cluster Specification (partition)
#> 
#> Main Arguments:
#>   k = 3
#> 
#> Computational engine: stats

Created on 2022-07-10 by the reprex package (v2.0.1)

EmilHvitfeldt avatar Jul 10 '22 22:07 EmilHvitfeldt