gpt4 book ai didi

r - R 中 h2o 包中的 predict.H2OModel() 是否为 h2o.randomForest() 模型提供 OOB 预测?

转载 作者:行者123 更新时间:2023-12-04 10:12:55 25 4
gpt4 key购买 nike

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

其实在我试过的3-4个例子中,似乎是predict.H2OModel()的结果更接近于来自 predict.randomForest() 的非 OOB 预测来自 randomForest包比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's h2o.predict()不提供 OOB 数据的预测。您必须使用 newdata = 指定要预测的数据集范围。所以当你有 newdata=d.h2o那么您将得到 d.h2o 的预测您指定的数据框。

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

关于r - R 中 h2o 包中的 predict.H2OModel() 是否为 h2o.randomForest() 模型提供 OOB 预测?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50458586/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com