I am triyng to fit many glm
models to my dataset, to select the best performing one, using the tidymodels
package. Since I'd like to try different combinations of preprocessing and model specifications, I am using the workflow_set()
function to generate them, and workflow_map()
to fit them and get performance metrics.
However, when applying workflow_map()
to the workflows, I get a cryptic error:
The most I could discover is that this error is returned by the function check_fn()
whitin the workflow_map()
function, but I don't understand the underlying problem in my code.
How can I use a glm model within a workflow_set
?
library(tidyverse)
library(tidymodels)
data("mtcars")
glm_recipe = recipe(hp ~ disp, data = mtcars)
glm_model = linear_reg() %>%
set_engine("glm", family = stats::gaussian("log"))
glm_workflows = workflow_set(list(glm_recipe), list(glm_model))
# fitting and predicting works
glm_workflows %>% workflow("recipe_linear_reg") %>% fit(mtcars) %>% predict(mtcars)
#> # A tibble: 32 x 1
#> .pred
#>
#> 1 117.
#> 2 117.
#> 3 103.
#> 4 151.
#> 5 195.
#> 6 138.
#> 7 195.
#> 8 113.
#> 9 112.
#> 10 120.
#> # ... with 22 more rows
# this doesn't work
workflow_map(glm_workflows)
#> Error in if (rlang::call_name(x) == "tune") {: argument is of length zero
#> Execution stopped; returning current results
#> # A workflow set/tibble: 1 x 4
#> wflow_id info option result
#>
#> 1 recipe_linear_reg
Created on 2022-06-02 by the reprex package (v2.0.1)
