R-H2O-如何获得训练有素的模型预测/概率? [英] R - H2O- How can I get my trained model predictions/probabilities?

查看:79
本文介绍了R-H2O-如何获得训练有素的模型预测/概率?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am running a classification model in H2O R. I would like to extract fitted model predictions for my training dataset.

代码:

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]

推荐答案

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

Here is a simple example of how to extract the cross-validated predictions from a trained H2O model in R (using the Iris dataset).

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:

The cvpreds object is an H2OFrame that looks like this:

> 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] 

这篇关于R-H2O-如何获得训练有素的模型预测/概率?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆