【问题标题】:Parallel random Forest missing MSE and R-squared平行随机森林缺少 MSE 和 R 平方
【发布时间】:2011-10-25 04:05:49
【问题描述】:

我运行一个非并行的 randomForest 对象没有问题:

> rf <- randomForest(t2[,-c(1,2,7,12)],t2[,2],
+                    ,sampsize=c(10000),do.trace=F,importance=TRUE,ntree=1,,forest=TRUE)
Warning message:
In randomForest.default(t2[, -c(1, 2, 7, 12)], t2[, 2], , sampsize = c(10000),  :
  The response has five or fewer unique values.  Are you sure you want to do regression?
> rf

Call:
 randomForest(x = t2[, -c(1, 2, 7, 12)], y = t2[, 2], ntree = 1,      sampsize = c(10000), importance = TRUE, do.trace = F, forest = TRUE) 
               Type of random forest: regression
                     Number of trees: 1
No. of variables tried at each split: 2

          Mean of squared residuals: 0.07444926
                    % Var explained: -19.36
> rf$rsq
[1] -0.1936248

现在我使用并行的东西运行相同的代码并且没有得到 MSE 或 % Var Explained:

> library("foreach")
> library("doSNOW")
> registerDoSNOW(makeCluster(2, type="SOCK"))
> 
> 
> 
> rf <- foreach(ntree = rep(1, 2), .combine = combine, .packages = "randomForest") %dopar%
+ randomForest(t2[,-c(1,2,7,12)],t2[,2],
+                    ,sampsize=c(10000),do.trace=F,importance=TRUE,ntree=1,,forest=TRUE)
> rf

Call:
 randomForest(x = t2[, -c(1, 2, 7, 12)], y = t2[, 2], ntree = 1,      sampsize = c(10000), importance = TRUE, do.trace = F, forest = TRUE) 
               Type of random forest: regression
                     Number of trees: 2
No. of variables tried at each split: 2

> rf$rsq
NULL

知道我做错了什么吗?谢谢。

【问题讨论】:

    标签: r


    【解决方案1】:

    不是并行位,而是使用 randomForest 包中的combine。引用?combine:

    混淆、err.rate、mse 和 rsq 组件(以及 测试组件中的相应组件(如果存在))的 组合对象将为 NULL。

    所以你必须使用预测值自己计算这些东西。

    【讨论】:

      猜你喜欢
      • 2019-01-29
      • 2019-07-21
      • 2020-09-20
      • 2021-08-17
      • 2012-02-01
      • 2017-03-26
      • 2018-01-18
      • 2019-05-04
      • 1970-01-01
      相关资源
      最近更新 更多