我一直在将 H2O.ai(版本 3.10.3.6)与 R 结合使用。
我正在努力用 h2o.glm 复制 glm 的结果。我期望得到完全相同的结果(在这种情况下,根据均方误差进行评估),但我发现 h2o 的准确性一定更差。由于我的模型是高斯模型,因此我希望这两种情况都是普通最小二乘(或最大似然)回归。
这是我的例子:
train <- model.matrix(~., training_df)
test <- model.matrix(~., testing_df)
model1 <- glm(response ~., data=data.frame(train))
yhat1 <- predict(model1 , newdata=data.frame(test))
mse1 <- mean((testing_df$response - yhat1)^2) #5299.128
h2o_training <- as.h2o(train)[-1,]
h2o_testing <- as.h2o(test)[-1,]
model2 <- h2o.glm(x = 2:dim(h2o_training)[2], y = 1,
training_frame = h2o_training,
family = "gaussian", alpha = 0)
yhat2 <- h2o.predict(model2, h2o_testing)
yhat2 <- as.numeric(as.data.frame(yhat2)[,1])
mse2 <- mean((testing_df$response - yhat2)^2) #8791.334
h2o 模型的 MSE 高出 60%。我的假设 glm ≈ h2o.glm 是错误的吗?我将尽快提供一个示例数据集(训练数据集是机密的,350000 行 x 350 列)。
一个额外的问题:出于某种原因,as.h2o 添加了一行充满 NA 的额外行,以便 h2o_training 和 h2o_testing 多了一行。在构建模型之前删除它(就像我在这里所做的:as.h2o(train)[-1,])不会影响回归性能。没有 NA 值传递给 glm 或 h2o.glm;即训练矩阵没有 NA 值。