Skip to content

Instantly share code, notes, and snippets.

@siegfried
Created December 16, 2020 06:55
Show Gist options
  • Save siegfried/153b0a84dae1716fceb7fdecf2c76b8b to your computer and use it in GitHub Desktop.
Save siegfried/153b0a84dae1716fceb7fdecf2c76b8b to your computer and use it in GitHub Desktop.
tune_bayes() example on `doRedis`
library(tidymodels)
library(modeldata)
data(cells)
set.seed(2369)
tr_te_split <- initial_split(cells %>% select(-case), prop = 3/4)
cell_train <- training(tr_te_split)
cell_test <- testing(tr_te_split)
set.seed(1697)
folds <- vfold_cv(cell_train, v = 10)
library(themis)
cell_pre_proc <-
recipe(class ~ ., data = cell_train) %>%
step_YeoJohnson(all_predictors()) %>%
step_normalize(all_predictors()) %>%
step_pca(all_predictors(), num_comp = tune()) %>%
step_downsample(class)
svm_mod <-
svm_rbf(mode = "classification", cost = tune(), rbf_sigma = tune()) %>%
set_engine("kernlab")
svm_wflow <-
workflow() %>%
add_model(svm_mod) %>%
add_recipe(cell_pre_proc)
svm_set <- parameters(svm_wflow)
svm_set <-
svm_set %>%
update(num_comp = num_comp(c(0L, 20L)))
set.seed(12)
library(doRedis)
registerDoRedis("debug_jobs") # No Redis worker is created.
search_res <-
svm_wflow %>%
tune_bayes(
resamples = folds,
param_info = svm_set,
initial = 5,
iter = 10,
metrics = metric_set(roc_auc),
control = control_bayes(no_improve = 5, verbose = TRUE)
)
removeQueue("debug_jobs")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment