我正在R中尝试在一个广泛的遗传数据集(662 x 35350)上进行R randomForest分析 . 除结果外的所有变量都是数字,其中99%是二进制0/1 . 我对R randomForest()非常熟悉,但之前只使用过5000-10000个变量的数据集 . 下一个计划的分析阶段将是一个包含数百万个变量的异常大的数据集,因此我有动力找到解决这个问题的方法 .

我的理解是R randomForest对变量的数量没有固有的限制,我知道我已经读过10万个变量数的已发表的工作 . 当我尝试对完整数据集进行分析时(设置ntree = 100,我得到:“错误:protect():保护堆栈溢出”

无论数据集是数据框(如最初提供的)还是将其转换为矩阵,都是如此 . 当我将运行提交到集群进行并行处理时,我发现在执行代码时我的所有内核都在运行 . 我也看到,在任何情况下,我的RAM使用率都接近机器的限制(48 GB) . 在执行尝试期间,它最多会占据大约16%的RAM . (我在办公室的512 GB RAM机器上也遇到了同样的问题,它的使用率从未超过5%) .

我已经尝试了在线发现的几种解决方案,包括之前的stackoverflow帖子中的一个(Increasing (or decreasing) the memory available to R processes) . 我在2009年尝试了BobbyShaftoe提供的指令(在快捷方式选项卡的属性中添加了--max-mem-size = 49000M和--max-vsize = 49000M),但这阻止了R正常打开 . 我也尝试在命令行中运行这些命令,但这些命令生成:'--max-ppsize' /' - max-vsize = 5000M“不被识别为内部或外部命令,可操作程序或批处理文件 .

我也阅读了这篇文章中提出的建议:How to improve randomForest performance? . 在完成至少一次具有完整功能集的运行之前,我无法减少功能的数量 . (另外,我不确定问题是RAM本身 . )

我在Windows 7上运行Revolution R 7.2(64位) . 我的内存限制设置为49807 Mb,但我不确定memory.limit是否特定地解决了允许的保护堆栈大小 .

将数据集分解为较小的变量块(这确实解决了堆栈溢出问题)并不能解决分析问题 . 是否有关于可能允许对完整数据集进行分析的R设置的建议?

##########################################
# input DF
##########################################
object.size(inputDF) # 191083664 bytes (as matrix, size=189391088 bytes, not much smaller)
dim(inputDF) # 662 x 35350 

##########################################
#Load necessary packages into R's memory
##########################################
require(iterators)
require(foreach)
require(parallel)
require(doParallel)
require(randomForest)

###########################################
# Get the number of available logical cores
###########################################
cores <- detectCores()
cores #12

###########################################
# Print info on computer, OS, cores
###########################################
print(paste('Processor: ', Sys.getenv('PROCESSOR_IDENTIFIER')), sep='')
print(paste('OS: ', Sys.getenv('OS')), sep='')
print(paste('Cores: ', cores, sep=''))

###########################################################################
# Setup clusters via parallel/DoParallel
###########################################################################
cl.spec <- rep("localhost", 10)
cl <- makeCluster(cl.spec, type="SOCK")
registerDoParallel(cl, cores=10)

###########################################################################
# RUN RANDOM FOREST
###########################################################################
system.time(forestOUT<- randomForest(as.factor(Dx01) ~ .,
data=inputDF,
do.trace = 10, 
ntree=100,
mtry =  sqrt(ncol(inputDF)), 
nodesize = 0.1*nrow(inputDF),
importance=T, 
proximity=F,
replace=TRUE,
keep.forest=TRUE))

stopCluster(cl)

见sessionInfo()

#Language: R
#OS: Windows 7
sessionInfo()
#R version 3.0.3 (2014-03-06)
#Platform: x86_64-w64-mingw32/x64 (64-bit)
#
#locale:
#[1] LC_COLLATE=English_Canada.1252  LC_CTYPE=English_Canada.1252    LC_MONETARY=English_Canada.1252 LC_NUMERIC=C                   
#[5] LC_TIME=English_Canada.1252    
#
#attached base packages:
 #[1] stats4    parallel  splines   grid      stats     graphics  grDevices utils     datasets  methods   base     
#
#other attached packages:
 #[1] QuantPsyc_1.5         boot_1.3-13           perturb_2.05          RCurl_1.95-4.5        bitops_1.0-6          car_2.0-22           
 #[7] reprtree_0.6          plotrix_3.5-10        rpart.plot_1.4-5      sqldf_0.4-7.1         RSQLite.extfuns_0.0.1 RSQLite_1.0.0        
#[13] gsubfn_0.6-6          proto_0.3-10          XML_3.98-1.1          RMySQL_0.9-3          DBI_0.3.1             mlbench_2.1-1        
#[19] polycor_0.7-8         sfsmisc_1.0-26        quantregForest_0.2-3  tree_1.0-35           maptree_1.4-7         cluster_1.15.3       
#[25] mice_2.22             VIM_4.0.0             colorspace_1.2-4      randomForest_4.6-10   ROCR_1.0-5            gplots_2.15.0        
#[31] caret_6.0-37          partykit_0.8-0        biomaRt_2.18.0        NCBI2R_1.4.6          snpStats_1.12.0       betareg_3.0-5        
#[37] arm_1.7-07            lme4_1.1-7            Rcpp_0.11.3           Matrix_1.1-4          nlme_3.1-118          mvtnorm_1.0-1        
#[43] taRifx_1.0.6          sos_1.3-8             brew_1.0-6            R.utils_1.34.0        R.oo_1.18.0           R.methodsS3_1.6.1    
#[49] rattle_3.3.0          jsonlite_0.9.13       httpuv_1.3.2          httr_0.5              gmodels_2.15.4.1      ggplot2_1.0.0        
#[55] JGR_1.7-16            iplots_1.1-7          JavaGD_0.6-1          party_1.0-18          modeltools_0.2-21     strucchange_1.5-0    
#[61] sandwich_2.3-2        zoo_1.7-11            pROC_1.7.3            e1071_1.6-4           psych_1.4.8.11        gtools_3.4.1         
#[67] functional_0.6        modeest_2.1           stringi_0.3-1         languageR_1.4.1       utility_1.3           data.table_1.9.4     
#[73] xlsx_0.5.7            xlsxjars_0.6.1        rJava_0.9-6           snow_0.3-13           doParallel_1.0.8      iterators_1.0.7      
#[79] foreach_1.4.2         reshape2_1.4          reshape_0.8.5         plyr_1.8.1            xtable_1.7-4          stringr_0.6.2        
#[85] foreign_0.8-61        Hmisc_3.14-6          Formula_1.1-2         survival_2.37-7       class_7.3-11          MASS_7.3-35          
#[91] nnet_7.3-8            Revobase_7.2.0        RevoMods_7.2.0        RevoScaleR_7.2.0      lattice_0.20-27       rpart_4.1-5          
#
#loaded via a namespace (and not attached):
 #[1] abind_1.4-0         acepack_1.3-3.3     BiocGenerics_0.8.0  BradleyTerry2_1.0-5 brglm_0.5-9         caTools_1.17.1      chron_2.3-45       
 #[8] coda_0.16-1         codetools_0.2-9     coin_1.0-24         DEoptimR_1.0-2      digest_0.6.4        flexmix_2.3-12      gdata_2.13.3       
#[15] glmnet_1.9-8        gtable_0.1.2        KernSmooth_2.23-13  latticeExtra_0.6-26 lmtest_0.9-33       minqa_1.2.4         munsell_0.4.2      
#[22] nloptr_1.0.4        pkgXMLBuilder_1.0   png_0.1-7           RColorBrewer_1.0-5  revoIpe_1.0         robustbase_0.92-2   scales_0.2.4       
#[29] sp_1.0-16           tcltk_3.0.3         tools_3.0.3         vcd_1.3-2