确实预测.来自 R 中 h2o 包的 H2OModel() 给出了 h2o.randomForest() 模型的 OOB



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

事实上,在我尝试过的 3-4 个示例中,predict.H2OModel()的结果似乎更接近来自randomForestpredict.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 票证来指定您是否需要 oob 指标(请注意,此票证还链接到另一个票证,这有助于阐明当前如何为随机森林报告训练指标(。

最新更新