我正在尝试使用foreach包运行随机林进行并行处理。这是我正在运行的代码。
library(doParallel)
library(doMC)
library(foreach)
library(randomForest)
Train <- read.csv("Train_Parallel.csv")
Test <- read.csv("Test_Parallel.csv")
Scoring <- read.csv("Scoring_Parallel.csv")
cores = detectCores()-1
cl = makeCluster(cores)
registerDoParallel(cl)
startparallel <- Sys.time()
rf_parallel <- foreach(ntree=rep(400, cores), .combine=combine, .multicombine=TRUE,
.packages='randomForest') %dopar% {
randomForest(target ~ .,
data=Train,
importance=TRUE,
ntree=ntree,
mtry = 25)
}
endparallel <- Sys.time()
stopCluster(cl)
endparallel - startparallel
并行执行代码按预期运行。但是,当我针对我的训练和测试数据集运行预测函数时,我得到以下错误。我做错了什么?
> Train$Predicted <- predict(rf_parallel, Train)
Error in UseMethod("predict") :
no applicable method for 'predict' applied to an object of class "list"
> Test$Predicted <- predict(rf_parallel, Test)
Error in UseMethod("predict") :
no applicable method for 'predict' applied to an object of class "list"
答案 0 :(得分:0)
确保randomForest :: combine未被dplyr :: combine或其他东西掩盖