Parallel Processing in R in caret

久未见 提交于 2021-02-05 20:29:34

问题


It is given in the caret documentation that to allow parallel processing the following code works

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

But in the latest R version(3.4) the package doMC is not available. Can anyone let me know of any other way to do parallel processing?

Update : What Roman suggested worked. DoMC is not available for windows. For windows use doParallel package cls = makeCluster(no of cores to use) and then registerDoParallel(cls) . Also make sure allowParallel is set to TRUE in trControl.


回答1:


doMC taps into the power of package multicore to calculate in distributed/parallel mode. This is fine, if you're on supported platforms, which Windows isn't.

You can use another framework, like parallel which comes shipped with R. To do so, you will need package doParallel which works on all three major platforms.




回答2:


Usually I do it like this adding allowParallel= TRUE :

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



回答3:


Just to expand on the implementation of the previous answers and basically using the Caret package documentation, here is a recipe that works for me:

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()


来源:https://stackoverflow.com/questions/44774516/parallel-processing-in-r-in-caret

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!