The following example illustrates the parameter tuning for the cells dataset using the tune package. However, if I try to switch from the tune packages grid() to finetunes tune_race_anova(), I am getting the following error message: "Error: There were no valid metrics for the ANOVA model."
With my reprex you can try both methods:
suppressPackageStartupMessages(library(tidymodels))
suppressPackageStartupMessages(library(doParallel))
suppressPackageStartupMessages(library(recipeselectors))
suppressPackageStartupMessages(library(finetune))
data(cells, package = "modeldata")
cells <- cells %>% select(-case)
set.seed(31)
split <- initial_split(cells, prop = 0.8)
train <- training(split)
test <- testing(split)
rec <-
recipe(class ~ ., data = train) %>%
step_corr(all_predictors(), threshold = 0.9) %>%
step_select_roc(all_predictors(), outcome = "class", top_p = tune())
# xgboost model
xgb_spec <- boost_tree(
trees = tune(),
tree_depth = tune(), min_n = tune(),
loss_reduction = tune(),
sample_size = tune(), mtry = tune(),
learn_rate = tune(),
stop_iter = tune()
) %>%
set_engine("xgboost") %>%
set_mode("classification")
# grids
xgb_grid <- grid_latin_hypercube(
trees(),
tree_depth(),
min_n(),
loss_reduction(),
sample_size = sample_prop(),
finalize(mtry(), train),
learn_rate(),
stop_iter(range = c(5L,50L)),
size = 5
)
rec_grid <- grid_latin_hypercube(
parameters(rec) %>%
update(top_p = top_p(c(0,30))) ,
size = 5
)
comp_grid <- merge(xgb_grid, rec_grid)
model_metrics <- metric_set(roc_auc)
rs <- vfold_cv(cells)
ctrl <- control_race(pkgs = "recipeselectors")
#ctrl <- control_grid(pkgs = "recipeselectors")
# tune
cores <- parallel::detectCores(logical = FALSE)
cl <- makePSOCKcluster(cores)
registerDoParallel(cl)
set.seed(234)
rfe_res <-
xgb_spec %>%
tune_race_anova(
#tune_grid(
preprocessor = rec,
resamples = rs,
grid = comp_grid,
control = ctrl
)
stopCluster(cl)
