【发布时间】:2018-10-31 16:26:36
【问题描述】:
我无法从文档中判断 R 中 h2o 包中的 predict.H2OModel() 函数是否为使用 h2o.randomForest() 构建的随机森林模型提供 OOB 预测。
事实上,在我尝试过的 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)
【问题讨论】:
标签: r random-forest h2o