gpt4 book ai didi

r - 为什么指定 sampsize 不能加速 randomForest?

转载 作者:行者123 更新时间:2023-11-30 08:58:45 24 4
gpt4 key购买 nike

我正在尝试对 this large dataset 运行随机森林回归在 R 中使用包 randomForest。我遇到了所需计算时间的问题,即使与 doSNOW 和 10-20 个内核并行也是如此。我认为我误解了函数 randomForest 中的“sampsize”参数。当我将数据集子集为 100,000 行时,我可以在 9-10 秒内构建 1 棵树。

training = read.csv("training.csv")
t100K = sample_n(training, 100000)
system.time(randomForest(tree~., data=t100K, ntree=1, importance=T)) #~10sec

但是,当我在运行 randomForest 的过程中使用 sampsize 参数从完整数据集中采样 100,000 行时,相同的 1 棵树需要几个小时。

system.time(randomForest(tree~., data=training, sampsize = ifelse(nrow(training<100000),nrow(training), 100000), ntree=1, importance=T)) #>>100x as long. Why?

显然,我最终会运行 >>1 棵树。我在这里缺少什么?谢谢。

最佳答案

你的括号有点不对。请注意以下陈述之间的区别。您目前拥有:

ifelse(nrow(mtcars<10),nrow(mtcars), 10)

计算 bool 矩阵 mtcars<10 中的行数有TRUE对于 mtcars 中小于 10 的每个元素,以及 FALSE否则。你想要:

ifelse(nrow(mtcars)<10,nrow(mtcars), 10)

希望这有帮助。

关于r - 为什么指定 sampsize 不能加速 randomForest?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49086450/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com