簡體   English   中英

插入符號中的 R 中的並行處理

[英]Parallel Processing in R in caret

在插入符號文檔中給出了允許並行處理以下代碼的工作

library(doMC) 
registerDoMC(cores = 5) 
## All subsequent models are then run in parallel

但是在最新的 R 版本(3.4)中,軟件包 doMC 不可用。 任何人都可以讓我知道進行並行處理的任何其他方式嗎?

更新:羅馬建議的工作。 DoMC 不適用於 Windows。 對於 Windows,使用 doParallel 包cls = makeCluster(no of cores to use)然后registerDoParallel(cls) 還要確保在 trControl 中將 allowParallel 設置為 TRUE。

doMC利用封裝multicore的強大功能以分布式/並行模式進行計算。 這很好,如果您使用的是受支持的平台,而 Windows 則不是。

您可以使用另一種框架,例如 R 附帶的parallel 。為此,您需要在所有三個主要平台上運行的軟件包doParallel

通常我會這樣做,添加allowParallel= TRUE

svmopt.caret=train(Y~.,data=nearsep1,method="svmLinear",
                   trControl=trainControl(method="cv",number=10,search="grid"),
                   tuneGrid=paramgrid,
                   allowParallel=TRUE)

只是為了擴展先前答案的實現並基本上使用Caret 包文檔,這里有一個對我有用的方法:

set.seed(112233)
library(parallel) 
# Calculate the number of cores
no_cores <- detectCores() - 1

library(doParallel)
# create the cluster for caret to use
cl <- makePSOCKcluster(no_cores)
registerDoParallel(cl)

# do your regular caret train calculation enabling
# allowParallel = TRUE for the functions that do
# use it as part of their implementation. This is
# determined by the caret package.

stopCluster(cl)
registerDoSEQ()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM