R 中 h2o 包中的 predict.H2OModel() 是否给出了 h2o.randomForest() 模型的 OOB 预测?

Does predict.H2OModel() from h2o package in R give OOB predictions for h2o.randomForest() models?

我无法从文档中判断 R 中 h2o 包中的 predict.H2OModel() 函数是否为使用 h2o.randomForest() 构建的随机森林模型提供了 OOB 预测。

事实上,在我试过的 3-4 个例子中,predict.H2OModel() 的结果似乎更接近 predict.randomForest()randomForest 的非 OOB 预测包比 OOB 包。

有谁知道它们是不是 OOB 预测?如果不是,您知道如何获得 h2o.randomForest() 模型的 OOB 预测吗?

示例:

set.seed(123)
library(randomForest)
library(h2o)

data(mtcars)
d = mtcars[,c('mpg', 'cyl', 'disp', 'hp', 'wt' )]

## define some common settings for both random forests
n.trees=1000
mtry = 3  
min.node = 3

## prep for h2o.randomForest
h2o.init()  
d.h2o= as.h2o(d) 
x.names = colnames(d)[2:5] ## predictors

## fit both models
set.seed(123); 
rf  =     randomForest(mpg ~ .,                      data = d    ,  ntree=n.trees,   mtry = mtry, nodesize=min.node)
h2o = h2o.randomForest(y='mpg', x=x.names, training_frame = d.h2o, ntrees=n.trees, mtries = mtry, min_rows=min.node)

## Correct way and incorrect way of getting OOB predictions for a randomForest model. Not sure about h2o model. 
d$rf.oob.pred =           predict(rf)                  ## Gives OOB predictions
d$rf.pred     =           predict(rf , newdata=d    )  ## Doesn't give OOB predictions.
d$h2o.pred    = as.vector(predict(h2o, newdata=d.h2o)) ## Not sure if this is OOB or not.  

## d$h2o.pred seems more similar to d$rf.pred than d$rf.oob.pred, 
## suggesting that predict.H2OModel() might not give OOB predictions.
mean((d$rf.pred     - d$h2o.pred)^2)
mean((d$rf.oob.pred - d$h2o.pred)^2)

H2O 的 h2o.predict() 不提供 OOB 数据的预测。您必须使用 newdata = 参数指定要预测的数据集。因此,当您拥有 newdata=d.h2o 时,您将获得对您指定的 d.h2o 数据框的预测。

目前尚无获得oob数据预测的方法。但是,有一个 jira ticket 指定您是否需要 oob 指标(请注意,此票证还链接到另一张票证,这有助于阐明当前如何报告随机森林的训练指标)。