LoginSignup

This article is a Private article. Only a writer and users who know the URL can access it.
Please change open range to public in publish setting if you want to share this article with other users.

More than 5 years have passed since last update.

Rのparallelパッケージを使ってRandomForestを並列化

Last updated at Posted at 2016-03-25

:arrow_forward: 通常と並列化の比較

:small_blue_diamond:通常のランダムフォレスト

library(randomForest)
library(kernlab)

data(spam)
set.seed(777)
system.time(fit.rf<-randomForest(type~.,data=spam,ntree=1000))
ユーザ システム 経過
21.584 0.213 21.919

:small_blue_diamond:並列化のランダムフォレスト

library(parallel)
cores<-detectCores()
cl<-makeCluster(cores,type="PSOCK")
invisible(clusterEvalQ(
    cl,{
        library(randomForest)
        library(kernlab)
        data(spam)
    }))
set.seed(123)
clusterSetRNGStream(cl)
print(system.time(res.pa<-parLapply(cl,rep(250,cores),function(ntree) randomForest(type~.,data=spam,ntree=ntree))))
ユーザ システム 経過
0.166 0.166 10.934

:arrow_forward: 並列化方法解説

Rのsnowパッケージを使ってrandomForestを並列化

  • クラスターの生成
cores<-detectCores()
cl<-makeCluster(cores,type="PSOCK")

参考資料

0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up