Is there a way to avoid repetitive warnings when tuning many models with workflow_map using parallel processing? In sequential mode, these get nicely summarised in the console output, but not with parallel workers, see reprex below.
In my real application, I tune many models over night and like to check their fitting times through the console output. Often, however, there are so many repetitive warnings (mostly related to yardstick rsq calculation and division by zero warnings) which occupy all console space so I cannot see the logging for most models anymore.
library(tidyverse)
library(tidymodels)
library(future)
options(tidymodels.dark = TRUE) #lighter colors.
moddata <-
concrete |>
summarise(compressive_strength = mean(compressive_strength), .by = c(cement:age)) |>
slice(1:100)
#initial split
set.seed(432)
split <- initial_split(moddata)
#recipe
rec <-
recipe(compressive_strength ~ ., data = training(split)) |>
step_normalize(all_predictors())
#model specs
lin_spec <-
linear_reg()
lin_reg_spec <-
linear_reg(penalty = tune(), mixture = tune()) %>%
set_engine("glmnet")
#worflowset
wfset <-
workflow_set(
preproc = list(rec = rec),
models = list(
lin = lin_spec,
lin_reg = lin_reg_spec
)
)
wfset
#> # A workflow set/tibble: 2 x 4
#> wflow_id info option result
#> <chr> <list> <list> <list>
#> 1 rec_lin <tibble [1 x 4]> <opts[0]> <list [0]>
#> 2 rec_lin_reg <tibble [1 x 4]> <opts[0]> <list [0]>
#resammples
set.seed(1265)
folds <- vfold_cv(training(split), v = 5, repeats = 1)
#set parallel
plan(multisession, workers = 5)
#plan(sequential)
# #ctrl
grid_ctrl <-
control_grid(
save_pred = FALSE,
parallel_over = "resamples",
pkgs = NULL,
save_workflow = FALSE
)
#fit
fit_results <-
wfset |>
workflow_map("tune_grid",
seed = 1563,
resamples = folds,
grid = 2,
control = grid_ctrl,
verbose = TRUE)
#> i No tuning parameters. `fit_resamples()` will be attempted
#> i 1 of 2 resampling: rec_lin
#> ! Fold1: preprocessor 1/1:
#> ! The following column has zero variance so scaling cannot be used: f...
#> i Consider using ?step_zv (`?recipes::step_zv()`) to remove those columns
#> before normalizing.
#> ! Fold1: preprocessor 1/1, model 1/1 (predictions): prediction from rank-deficient fit; consider predict(., rankdeficient="NA")
#> ! Fold2: preprocessor 1/1:
#> ! The following column has zero variance so scaling cannot be used: f...
#> i Consider using ?step_zv (`?recipes::step_zv()`) to remove those columns
#> before normalizing.
#> ! Fold2: preprocessor 1/1, model 1/1 (predictions): prediction from rank-deficient fit; consider predict(., rankdeficient="NA")
#> ! Fold3: preprocessor 1/1:
#> ! The following column has zero variance so scaling cannot be used: f...
#> i Consider using ?step_zv (`?recipes::step_zv()`) to remove those columns
#> before normalizing.
#> ! Fold3: preprocessor 1/1, model 1/1 (predictions): prediction from rank-deficient fit; consider predict(., rankdeficient="NA")
#> ! Fold4: preprocessor 1/1:
#> ! The following column has zero variance so scaling cannot be used: f...
#> i Consider using ?step_zv (`?recipes::step_zv()`) to remove those columns
#> before normalizing.
#> ! Fold4: preprocessor 1/1, model 1/1 (predictions): prediction from rank-deficient fit; consider predict(., rankdeficient="NA")
#> ! Fold5: preprocessor 1/1:
#> ! The following column has zero variance so scaling cannot be used: f...
#> i Consider using ?step_zv (`?recipes::step_zv()`) to remove those columns
#> before normalizing.
#> ! Fold5: preprocessor 1/1, model 1/1 (predictions): prediction from rank-deficient fit; consider predict(., rankdeficient="NA")
#> v 1 of 2 resampling: rec_lin (15.9s)
#> i 2 of 2 tuning: rec_lin_reg
#> ! Fold1: preprocessor 1/1:
#> ! The following column has zero variance so scaling cannot be used: f...
#> i Consider using ?step_zv (`?recipes::step_zv()`) to remove those columns
#> before normalizing.
#> ! Fold2: preprocessor 1/1:
#> ! The following column has zero variance so scaling cannot be used: f...
#> i Consider using ?step_zv (`?recipes::step_zv()`) to remove those columns
#> before normalizing.
#> ! Fold3: preprocessor 1/1:
#> ! The following column has zero variance so scaling cannot be used: f...
#> i Consider using ?step_zv (`?recipes::step_zv()`) to remove those columns
#> before normalizing.
#> ! Fold4: preprocessor 1/1:
#> ! The following column has zero variance so scaling cannot be used: f...
#> i Consider using ?step_zv (`?recipes::step_zv()`) to remove those columns
#> before normalizing.
#> ! Fold5: preprocessor 1/1:
#> ! The following column has zero variance so scaling cannot be used: f...
#> i Consider using ?step_zv (`?recipes::step_zv()`) to remove those columns
#> before normalizing.
#> v 2 of 2 tuning: rec_lin_reg (1.1s)
Created on 2024-12-07 with reprex v2.1.1