【问题标题】:R - H2O- How can I get my trained model predictions/probabilities?R - H2O- 如何获得训练有素的模型预测/概率?
【发布时间】:2017-08-20 15:09:21
【问题描述】:

我正在 H2O R 中运行分类模型。我想为我的训练数据集提取拟合模型预测。

代码:

train <- as.h2o(train)
test <- as.h2o(test)
y <- "class"
x <- setdiff(names(train), y)
family <- "multinomial"
nfolds <- 5 
gbm1 <- h2o.gbm(x = x, y = y, distribution = family,
            training_frame = train,
            seed = 1,
            nfolds = nfolds,
            fold_assignment = "Modulo",
            keep_cross_validation_predictions = TRUE)
h2o.getFrame(gbm1@model$cross_validation_predictions[[gbm1@allparameters$nfolds]]$name)[,2:4]

【问题讨论】:

  • 哪种型号?请粘贴您的代码示例,以便我了解您要执行的操作。我假设您希望对测试集而不是您的训练集进行预测...?
  • @ErinLeDell 添加了代码。不,我想得到我训练好的模型的预测。这是 gbm1 的拟合预测。
  • 好的,我明白了——你想要交叉验证的预测。感谢您的澄清。

标签: r h2o


【解决方案1】:

这是一个简单示例,说明如何从 R 中经过训练的 H2O 模型(使用 Iris 数据集)中提取交叉验证的预测。

library(h2o)
h2o.init(nthreads = -1)

data(iris)
train <- as.h2o(iris)
y <- "Species"
x <- setdiff(names(train), y)
family <- "multinomial"
nfolds <- 5 

gbm1 <- h2o.gbm(x = x, y = y, 
                distribution = family,
                training_frame = train,
                seed = 1,
                nfolds = nfolds,
                fold_assignment = "Modulo",
                keep_cross_validation_predictions = TRUE)

cvpreds_id <- gbm1@model$cross_validation_holdout_predictions_frame_id$name
cvpreds <- h2o.getFrame(cvpreds_id)

cvpreds 对象是一个 H2OFrame,如下所示:

> cvpreds
  predict    setosa   versicolor    virginica
1  setosa 0.9986012 0.0008965135 0.0005022631
2  setosa 0.9985695 0.0004486762 0.0009818434
3  setosa 0.9981387 0.0004777671 0.0013835724
4  setosa 0.9985246 0.0006259377 0.0008494549
5  setosa 0.9989924 0.0005033832 0.0005042294
6  setosa 0.9981410 0.0013581692 0.0005008536

[150 rows x 4 columns] 

【讨论】:

    猜你喜欢
    • 2018-11-03
    • 2019-06-07
    • 2019-10-10
    • 1970-01-01
    • 2018-06-21
    • 2019-03-04
    • 2021-06-22
    • 2020-03-18
    • 1970-01-01
    相关资源
    最近更新 更多