当方法设置为timelice时,并行化是否可以在插入符号包中工作?
我使用doMC注册内核:
library(parallel)
library(doMC)
numCores <- detectCores()
registerDoMC(numCores)
此示例按预期工作,所有内核均并行运行:
library(caret)
library(mlbench)
data(Sonar)
inTrain <- createDataPartition(y = Sonar$Class, p = .75, list = FALSE)
training <- Sonar[ inTrain,]
testing <- Sonar[-inTrain,]
grid_rf <- expand.grid(.mtry = c(2, 3, 4))
ctrl <- trainControl(method = "repeatedcv", number = 8, repeats = 2)
system.time({
rf <- train(Class ~ ., data = training, method = "rf", trControl = ctrl, ntree=50000, tuneGrid = grid_rf)
})
此示例未按预期运行,在短暂使用所有内核之后,大部分时间仅使用一个内核:
ctrl <- trainControl(method = "timeslice",
initialWindow = 10,
horizon = 1,
fixedWindow = TRUE,
allowParallel = TRUE)
system.time({
rf <- train(Class ~ ., data = training, method = "rf", trControl = ctrl, ntree=50000, tuneGrid = grid_rf)
})
这是预期的行为吗?我错过了文档中显而易见的内容吗?