r - 加速随机森林的建议

标签 r random-forest

我正在使用 randomForest 做一些工作打包,虽然它运行良好,但可能很耗时。有人对加快速度有什么建议吗?我正在使用带有双核 AMD 芯片的 Windows 7 盒子。我知道 R 不是多线程/处理器,但很好奇是否有任何并行包( rmpisnowsnowfall 等)适用于 randomForest东西。谢谢。

编辑:

我正在使用 rF 进行一些分类工作(0 和 1)。数据有大约 8-12 个变量列,训练集是 10k 行的样本,所以它的大小合适但并不疯狂。我正在运行 500 棵树,mtry 为 2、3 或 4。

编辑2:
这是一些输出:

> head(t22)
  Id Fail     CCUse Age S-TFail         DR MonInc #OpenLines L-TFail RE M-TFail Dep
1  1    1 0.7661266  45       2 0.80298213   9120         13       0  6       0   2
2  2    0 0.9571510  40       0 0.12187620   2600          4       0  0       0   1
3  3    0 0.6581801  38       1 0.08511338   3042          2       1  0       0   0
4  4    0 0.2338098  30       0 0.03604968   3300          5       0  0       0   0
5  5    0 0.9072394  49       1 0.02492570  63588          7       0  1       0   0
6  6    0 0.2131787  74       0 0.37560697   3500          3       0  1       0   1
> ptm <- proc.time()
> 
> RF<- randomForest(t22[,-c(1,2,7,12)],t22$Fail
+                    ,sampsize=c(10000),do.trace=F,importance=TRUE,ntree=500,,forest=TRUE)
Warning message:
In randomForest.default(t22[, -c(1, 2, 7, 12)], t22$Fail, sampsize = c(10000),  :
  The response has five or fewer unique values.  Are you sure you want to do regression?
> proc.time() - ptm
   user  system elapsed 
 437.30    0.86  450.97 
> 

最佳答案

foreach说明书包中有一个关于并行随机森林的部分
( Using The foreach Package ,第 5.1 节):

> library("foreach")
> library("doSNOW")
> registerDoSNOW(makeCluster(4, type="SOCK"))

> x <- matrix(runif(500), 100)
> y <- gl(2, 50)

> rf <- foreach(ntree = rep(250, 4), .combine = combine, .packages = "randomForest") %dopar%
+    randomForest(x, y, ntree = ntree)
> rf
Call:
randomForest(x = x, y = y, ntree = ntree)
Type of random forest: classification
Number of trees: 1000

如果我们想创建一个有 1000 棵树的随机森林模型,而我们的计算机有四个
核心,我们可以通过执行 randomForest 将问题分成四个部分函数四次,用 ntree参数设置为 250。当然,我们必须结合结果 randomForest对象,但 randomForest包带有一个名为 combine 的函数.

关于r - 加速随机森林的建议,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7830255/

相关文章:

r - 使用 R 在 randomForest 上执行交叉验证

r - 在 R 中以交互方式选择目录的独立于操作系统的方式

r - C5.0 树模型上的高度不平衡数据

apache-spark - 随机森林分类器 :To which class corresponds the probabilities

使用字典中的短语进行 R 情感分析

python - '值错误: could not convert string to float' in python sklearn

randomForestSRC采样方案

R 当前时间(以毫秒为单位)

r - 如何在ggplot中向geom_vline添加文本

python - python 中的邻近图