rparallel-processingr-caret

Caret in R: Set number of cores for allowParallel?


I am using R's caret package, and in the training function (train) I use the allowParallel Parameter, which works. However, it uses all of the cores, and since the training runs on my local PC I would rather leave one core for myself to be able to work while training models. Is there any way to do this?

From what I've gathered it seems that different model types might use different parallelization packages. I am working on windows, so I guess it's not using doMC (where I know how to set the number of cores...)


Solution

  • So after more research, I found a way to use the number of cores I want: train has the option to directly specify the number of cores to use with num.threads = 7 (for 7 out of 8 cores)

    rf_model<-train(Target~., data = df_tree_train, method = "ranger",
                    trControl = trainControl(method = "oob"
                                           , verboseIter  = TRUE
                                           , allowParallel = TRUE
                                           , classProbs = TRUE
                    )
                    , verbose = T
                    , tuneGrid = tuneGrid
                    , num.trees = 50
                    , num.threads = 7  # <- This one
    )