繁体   English   中英

对从并行处理创建的随机森林模型进行评分

[英]Scoring a random forest model created from parallel processing

我正在尝试使用 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" 

确保 randomForest::combine 没有被 dplyr::combine 或其他东西掩盖

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM