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)