我知道我可以在 R 中进行并行计算,但是我无法以与我的建模方法配合使用的方式对其进行设置。
这是我设置负载/设置并行计算的方式
library(doParallel) # Parallel Computing
cores <- detectCores() - 1
cluster <- makePSOCKcluster(cores)
registerDoParallel(cluster)
稍后在我的降价书中,我有以下代码来创建、调整和拟合使用多项式内核的支持向量机的工作流。
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)
我的问题是如何为以下内容启用并行计算?
tune_wf <- workflow() %>%
add_model(tune_spec) %>%
add_formula(win ~ .)