Closed spsanderson closed 1 year ago
This will make the workflow, something similar should work for fitting:
rec_obj <- recipes::recipe(mpg ~ ., data = mtcars)
tst <- create_model_spec(
.parsnip_eng = list("gee","lm"),
.mode = list("regression"),
.parsnip_fns = list("linear_reg")
)
tst <- tst %>%
dplyr::mutate(.model_id = dplyr::row_number()) %>%
dplyr::select(.model_id, dplyr::everything()) %>%
dplyr::mutate(.model_id = forcats::as_factor(.model_id)) %>%
dplyr::mutate(rec_obj = list(rec_obj))
models_tbl <- tst %>%
dplyr::group_split(.model_id)
wflw_list <- models_tbl %>%
purrr::imap(
.f = function(obj, id){
# Pull the model column and then pluck the model
mod <- obj %>% dplyr::pull(5) %>% purrr::pluck(1)
# Pull the recipe column and then pluck the recipe
rec_obj <- obj %>% dplyr::pull(6) %>% purrr::pluck(1)
# Create a safe add model function
safe_add_mod <- purrr::safely(
workflows::add_model,
otherwise = "Error",
quiet = FALSE
)
# Return the workflow object with recipe and model
ret <- workflows::workflow() %>%
workflows::add_recipe(rec_obj) %>%
safe_add_mod(mod)
# Pluck the result
res <- ret %>% purrr::pluck("result")
# Return the result
return(res)
}
)
Error: parsnip could not locate an implementation for `linear_reg` regression model specifications using the `gee` engine.
> wflw_list
[[1]]
[1] "Error"
[[2]]
══ Workflow ═══════════════════════════════════════════════════════════════════════════════════
Preprocessor: Recipe
Model: linear_reg()
── Preprocessor ───────────────────────────────────────────────────────────────────────────────
0 Recipe Steps
── Model ──────────────────────────────────────────────────────────────────────────────────────
Linear Regression Model Specification (regression)
Computational engine: lm
The following objects are being produced incorrectly
This stems from using
wflw[[1]]
in the code and not mapping a function to the list column object.To fix the
wflw
column make a helper function like so:Function:
Example: