我試圖通過R使用H2O構建多個模型,使用一個大型數據集(〜10GB)的子集。這些數據是價值一年的數據,我試圖建立51個模型(即,在第一週訓練,在第二週預測等),每週有大約1.5-2.5百萬行,其中有8個變量。R H2O - 內存管理
我在一個循環裏面做了這個,我知道並不總是R中最好的方法。我發現的另一個問題是H2O實體會累積先前的對象,所以我創建了一個函數來刪除它們中的所有對象主數據集除外。
h2o.clean <- function(clust = localH2O, verbose = TRUE, vte = c()){
# Find all objects on server
keysToKill <- h2o.ls(clust)$Key
# Remove items to be excluded, if any
keysToKill <- setdiff(keysToKill, vte)
# Loop thru and remove items to be removed
for(i in keysToKill){
h2o.rm(object = clust, keys = i)
if(verbose == TRUE){
print(i);flush.console()
}
}
# Print remaining objects in cluster.
h2o.ls(clust)
}
該腳本運行良好一段時間然後崩潰 - 通常與抱怨內存不足和交換到磁盤。
下面是一些僞代碼來描述過程
# load h2o library
library(h2o)
# create h2o entity
localH2O = h2o.init(nthreads = 4, max_mem_size = "6g")
# load data
dat1.hex = h2o.importFile(localH2O, inFile, key = "dat1.hex")
# Start loop
for(i in 1:51){
# create test/train hex objects
train1.hex <- dat1.hex[dat1.hex$week_num == i,]
test1.hex <- dat1.hex[dat1.hex$week_num == i + 1,]
# train gbm
dat1.gbm <- h2o.gbm(y = 'click_target2', x = xVars, data = train1.hex
, nfolds = 3
, importance = T
, distribution = 'bernoulli'
, n.trees = 100
, interaction.depth = 10,
, shrinkage = 0.01
)
# calculate out of sample performance
test2.hex <- cbind.H2OParsedData(test1.hex,h2o.predict(dat1.gbm, test1.hex))
colnames(test2.hex) <- names(head(test2.hex))
gbmAuc <- h2o.performance(test2.hex$X1, test2.hex$click_target2)@model$auc
# clean h2o entity
h2o.clean(clust = localH2O, verbose = F, vte = c('dat1.hex'))
} # end loop
我的問題是,如果有,是什麼,來管理一個獨立的實體數據和內存的正確方式(這不是在Hadoop或運行羣集 - 這種類型的進程只是一個大的EC2實例(〜64GB RAM + 12個CPU))?我應該在每個循環後殺死並重新創建H2O實體(這是原始過程,但每次從文件中讀取數據每次迭代會增加〜10分鐘)?在每個循環之後有沒有合適的方法來垃圾收集或釋放內存?
任何建議,將不勝感激。
你可以通過鍵刪除所有你想要的東西:'h2o.rm(localH2O,「keyDataWhichIWantDelete」)' – 2015-02-27 16:43:45