tune icon indicating copy to clipboard operation
tune copied to clipboard

tune_bayes does not finalize by itself

Open jxu opened this issue 1 year ago • 4 comments

bt_tune_grid <- bt_wf %>% tune_grid(resamples=comb4_set, 
                                    grid=20,
                                    control=control_grid(verbose=T),
                                    metrics=metric_set(roc_auc))

bt_bayes <- bt_wf %>% tune_bayes(comb4_set, 
                                 initial=bt_tune_grid,
                                 objective="roc_auc")

tune_grid is able to finalize mtry() itself, but tune_bayes fails with

A | error:   ℹ In index: 1.
               Caused by error in `.f()`:
               ! The parameter object contains unknowns.

And I do not know what to pass to param_info, because ?parameters is lacking (https://github.com/tidymodels/dials/issues/313).

I found an example online using extract_parameter_set_dials(bt_mod) %>% finalize(comb4_sample), but this is not mentioned anywhere in ?tune_bayes or ?finalize.

Even if I change the model to not tune mtry(), I still get the mysterious error

i Gaussian process model
✓ Gaussian process model
i Generating 5000 candidates
i Predicted candidates
Error in UseMethod("predict") : 
  no applicable method for 'predict' applied to an object of class "character"

jxu avatar Nov 07 '23 16:11 jxu

Thanks for the issue!

I don't have access to your bt_wf and comb4_set objects. Can you please provide a minimal reprex (reproducible example)? A reprex will help me troubleshoot and fix your issue more quickly.🙂

simonpcouch avatar Nov 07 '23 20:11 simonpcouch

It isn't specific to my particular workflow or dataset; here's a simple example

library(tidymodels)
library(xgboost)

mtcars <- mtcars %>% mutate(mpg = factor(mpg))

split <- initial_validation_split(mtcars)
rset <- validation_set(split)

bt_mod <- boost_tree("classification", mtry=tune())
bt_wf <- workflow() %>% 
  add_model(bt_mod) %>% 
  add_recipe(recipe(mpg ~ ., data=mtcars))

bt_wf %>% tune_grid(resamples=rset)  
# i Creating pre-processing data to finalize unknown parameter: mtry

bt_wf %>% tune_bayes(resamples=rset)  
# Error in `dials::grid_latin_hypercube()`:
# ! These arguments contain unknowns: `mtry`.
# ℹ See the `finalize()` function.

jxu avatar Nov 08 '23 17:11 jxu

Even if one passes the preprocessor, tune_bayes is not finalizing. Here a reprex

library(tidymodels)
library(xgboost)

split <- initial_split(mtcars)
bt_valid <- vfold_cv(training(split), v = 5)
bt_mod <- boost_tree("regression", mtry = tune(), trees = tune(), min_n = 5)
bt_rcp <- recipe(mpg ~ ., data = training(split))
bt_wf <- workflow() |> add_model(bt_mod) |> add_recipe(bt_rcp)

bt_wf |> tune_grid(preprocessor = bt_rcp, resamples = bt_valid, grid = 10)
bt_wf |> tune_bayes(preprocessor = bt_rcp, resamples = bt_valid, initial = 10)

This is quite relevant, because to solve it one has to "manually" update the parameter space or to create the grid.

marcozanotti avatar Jan 19 '24 08:01 marcozanotti

any update on this?

skawakita84 avatar Aug 06 '24 22:08 skawakita84