运行 randomForest in R 期间详细模式的解释

The explanation of the verbose mode during running randomForest in R

我是 R 中的 运行 randomForest,详细模式 (do.trace), 我想知道消息中各列的含义是什么。 我可以看到 ntree 是树的数量,OOB 是袋外样本的百分比,但是“1”和“2”是什么?

> rf.m <- randomForest(x = X.train, y=as.factor(y.train), do.trace=10)
ntree      OOB      1      2
   10:  32.03% 15.60% 82.47%
   20:  29.18% 10.51% 86.31%
   30:  27.44%  7.47% 88.57%
   40:  26.48%  5.29% 91.33%
   50:  25.92%  4.35% 91.96%
   ....

输出中的 12 列给出了每个 class 的 class 化错误。 OOB 值是 class 误差的加权平均值(由每个 class 中的观察分数加权)。

示例(改编帮助页面中的随机森林示例):

# Keep every 100th tree in the trace
set.seed(71)
iris.rf <- randomForest(Species ~ ., data=iris, importance=TRUE,
                        proximity=TRUE, do.trace=100)

ntree      OOB      1      2      3
  100:   6.00%  0.00%  8.00% 10.00%
  200:   5.33%  0.00%  6.00% 10.00%
  300:   6.00%  0.00%  8.00% 10.00%
  400:   4.67%  0.00%  8.00%  6.00%
  500:   5.33%  0.00%  8.00%  8.00%

第 100 棵树的 class 错误的加权平均值得出 6.0% 的 OOB 错误率,与上面跟踪中报告的完全一致。 (prop.table returns 物种的每个类别(每个 class)的观察分数)。我们将该元素乘以第 100 棵树的 class 误差,如上面的跟踪值所示,然后求和以获得所有 classes 的加权平均误差(OOB 误差)。

sum(prop.table(table(iris$Species)) * c(0, 0.08, 0.10))
[,1]
[1,] 0.06

如果你使用矩阵乘法,你可以避免需要使用求和,这里相当于dot/scalar/inner乘积:

prop.table(table(iris$Species)) %*% c(0, 0.08, 0.10)