1

I know that I can do parallel computing in R however I am having trouble setting it up in a way that it works with my modeling approach.

Here is how I set load / set up the parallel computing

library(doParallel) # Parallel Computing
cores <- detectCores() - 1
cluster <- makePSOCKcluster(cores)
registerDoParallel(cluster)

Later on in my markdown book, I have the following code to create, tune and fit a workflow for a support vector machine using a polynomial kernel.

tune_cv_folds <- vfold_cv(data = train_baked, v = 10)

tune_spec <- svm_poly(cost = tune(), degree = tune(), margin = tune()) %>% 
  set_engine("kernlab") %>%
  set_mode("classification")

tune_wf <- workflow() %>%
  add_model(tune_spec) %>%
  add_formula(win ~ .)

tune_res <- 
  tune_wf %>% 
  tune_grid(
    resamples = tune_cv_folds,
    grid = 10)

paramvalue <- tune_res %>% select_best("roc_auc")

fit <- svm_poly(cost = paramvalue$cost, degree = paramvalue$degree, margin = paramvalue$degree) %>% 
  set_engine("kernlab") %>%
  set_mode("classification")

wf <- workflow() %>% add_model(poly_fit) %>% add_formula(win ~.) %>% fit(data = train_baked)

poly_fit <- poly_wf  %>% pull_workflow_fit()
summary(poly_fit)

My question here is how do I enable parallel computing for the following?

tune_wf <- workflow() %>%
  add_model(tune_spec) %>%
  add_formula(win ~ .)
StupidWolf
  • 45,075
  • 17
  • 40
  • 72
  • Why do you add the tag `caret`? From your code, it doesn't seem that you use the `caret` package. However, if you have some knowledge of caret you can simply set a parallel backend, then the `train` function (the main function of the caret package, to fit a model) will use it automatically – Elia Apr 19 '21 at 08:21

0 Answers0