Parallel Processing in R in caret

前端 未结 3 398
佛祖请我去吃肉
佛祖请我去吃肉 2021-02-03 10:58

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

library(doMC) 
registerDoMC(cores = 5) 
## All subsequent mode         


        
相关标签:
3条回答
  • 2021-02-03 11:36

    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)
    
    0 讨论(0)
  • 2021-02-03 11:40

    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()
    
    0 讨论(0)
  • 2021-02-03 11:51

    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.

    0 讨论(0)
提交回复
热议问题