0

I'm using the caret package to train on a 14x21 matrix. The below script takes 65 seconds to process, which is awfully slow. I was wondering if there is any efficiency gains by utilizing the parallel packages in R? The PC I am running the code on has 16 cores, but I'm wondering if I need to insert %dopar% or some other script to facilitate speed.

library(caret)
library(foreach)  
library(parallel) 
library(doParallel)
library(ggplot2)

registerDoParallel(cores = 16) 
nCores <- detectCores(logical = FALSE)

# read data
Macro <- read.csv("P:/Earnest/Old/R/Input.csv")
x <- Macro[1:13,3:21]
x <- as.matrix(x)
x
y <- Macro[1:13,2:2]
y <- as.matrix(y)
y
t <- Macro[14:14,3:21]
t <- as.matrix(t)
t

#select trainControl

ctrl = trainControl(method = "cv", number = 5, repeats = 5, verboseIter = TRUE, savePredictions = TRUE)

methoda <- "randomGLM"

#round 1
fit <- caret::train(y = as.vector(y), 
                      x = x, 
                      method = methoda, 
                      trControl = ctrl,
                      preProc = c("center", "scale"))

a6 <- predict(fit ,t)
ZJAY
  • 2,517
  • 9
  • 32
  • 51
  • How many cores show load during these 65 seconds? – Ralf Stubner Sep 03 '18 at 04:40
  • Few questions on SO https://stackoverflow.com/questions/46119014/caret-train-binary-glm-fails-on-parallel-cluster-via-doparallel – Tung Sep 03 '18 at 04:52
  • https://stackoverflow.com/questions/48146558/caret-in-r-set-number-of-cores-for-allowparallel – Tung Sep 03 '18 at 04:53
  • @ Ralf Stubner 3 my machine has 16 cores, and I'm using registerDoParallel(cores = 16) - so I assume it is using all 16 cores? – ZJAY Sep 03 '18 at 08:09

0 Answers0