在R中的h2o包中,predict.H2OModel()函数是否会给出h2o.randomForest()模型的OOB预测?

4
我无法从文档中确定R语言中的h2o包中predict.H2OModel()函数是否为使用h2o.randomForest()构建的随机森林模型提供袋外预测。实际上,在我尝试的3-4个示例中,predict.H2OModel()的结果似乎更接近于来自randomForest包的predict.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)
1个回答

3

H2O的h2o.predict()不提供OOB数据的预测。您需要使用newdata=参数指定要进行预测的数据集。因此,当您使用newdata=d.h2o时,您将获得为您指定的d.h2o数据框架的预测。

目前没有方法可以获取OOB数据的预测结果。但是,有一个jira ticket可以指定是否需要OOB指标(请注意,此票据还链接到另一个票据,帮助澄清Random Forest当前如何报告训练指标)。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接