Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tune_bayes does not finalize by itself #752

Open
jxu opened this issue Nov 7, 2023 · 4 comments
Open

tune_bayes does not finalize by itself #752

jxu opened this issue Nov 7, 2023 · 4 comments

Comments

@jxu
Copy link

jxu commented Nov 7, 2023

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 (tidymodels/dials#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"
@simonpcouch
Copy link
Contributor

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.🙂

@jxu
Copy link
Author

jxu commented Nov 8, 2023

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.

@marcozanotti
Copy link

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.

@skawakita84
Copy link

any update on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants