ランダムフォレストをシリアルで実行すると、システムで8GBのRAMが使用されます。どのように並行して実行すると、8GBに保つことができますか?コードは次のとおりです。doSMPとforeachを使用した並列ランダムフォレストでは、メモリ使用量が大幅に増加します(Windows版)
install.packages('foreach')
install.packages('doSMP')
install.packages('randomForest')
library('foreach')
library('doSMP')
library('randomForest')
NbrOfCores <- 8
workers <- startWorkers(NbrOfCores) # number of cores
registerDoSMP(workers)
getDoParName() # check name of parallel backend
getDoParVersion() # check version of parallel backend
getDoParWorkers() # check number of workers
#creating data and setting options for random forests
#if your run this please adapt it so it won't crash your system! This amount of data uses up to 18GB of RAM.
x <- matrix(runif(500000), 100000)
y <- gl(2, 50000)
#options
set.seed(1)
ntree=1000
ntree2 <- ntree/NbrOfCores
gc()
#running serialized version of random forests
system.time(
rf1 <- randomForest(x, y, ntree = ntree))
gc()
#running parallel version of random forests
system.time(
rf2 <- foreach(ntree = rep(ntree2, 8), .combine = combine, .packages = "randomForest") %dopar% randomForest(x, y, ntree = ntree))
良い提案ですが、将来的に予測を行うためにはフォレストモデルが必要です(モデルを作成して後で新しいデータをスコアリングする必要があります)。マルチコアパッケージに関して:それはUnixのためでしかありません(私はWindows上です、cf.私の質問)。 – user1134616
@ user1134616もしそうなら、あなたはnon-Rランダムフォレストの実装だけに頼ることができます... – mbq