r-为什么我在h2o和插入符号::R2()中的测试数据集中得到的预测数据和实际数据之间的R2不同



我想在测试数据集中获得预测数据和实际数据之间的R2,为什么h2o.performance(m,test(的结果与carte::R2((或'lm'模型不同?

"h2o性能(m,test("为0.733401,"插入符号::R2(p,a("为0.7577784summary(lmm($r.square与"插入符号::R2(p,a("相同

示例代码:

library(h2o)
h <- h2o.init()
data <- as.h2o(iris)
part <- h2o.splitFrame(data, 0.7, seed = 123)
train <- part[[1]]
test <- part[[2]]
m <- h2o.glm(x=2:5,y=1,train, nfolds = 10, seed = 123)
summary(m)
predictions <- h2o.predict(m, test)
p <- as.data.frame(predictions)
a <- as.data.frame(test[1])
caret::R2(p,  a)
# 0.7577784
h2o.performance(m,  test)
# the R^2 is 0.733401
df <- data.frame(p=p, a=a)
lmm <- lm(predict ~ Sepal.Length, data =df)
summary(lmm)$r.squared
# the r.squared is 0.7577784

您可以获得以下训练指标:

m <- h2o.glm(x=2:5,y=1,train,validation_frame = test)

#We would ideally use a validation set. 
h2o.performance(m,test)
m@model$training_metrics

最新更新