首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在H2O中指定阻塞因子

在H2O中指定阻塞因子
EN

Stack Overflow用户
提问于 2017-09-19 17:14:59
回答 1查看 99关注 0票数 0

在R版本的H2O中,在训练/验证/测试集中拆分数据和/或进行交叉验证时,是否可以指定阻塞因子?

我正在处理一个临床数据集,其中包含来自同一患者的多个观察数据,这些数据应该在这些手术过程中保存在一起。

如果在H2O框架中不能做到这一点,那么关于如何在R中实现这一点并与H2O函数集成的建议将是很棒的。

谢谢!

EN

回答 1

Stack Overflow用户

发布于 2017-09-19 22:26:14

当使用H2O-3进行交叉验证时,您可以通过fold_column参数告诉训练算法一个观察值属于哪个折叠数。请参见:

  • http://docs.h2o.ai/h2o/latest-stable/h2o-docs/data-science/algo-params/fold_column.html

下面的代码示例(从上面的链接复制)显示了随机分配的折叠。但是,您也可以编写一段代码来专门为它们赋值。

代码语言:javascript
复制
library(h2o)
h2o.init()

# import the cars dataset:
# this dataset is used to classify whether or not a car is economical based on
# the car's displacement, power, weight, and acceleration, and the year it was made
cars <- h2o.importFile("https://s3.amazonaws.com/h2o-public-test-data/smalldata/junit/cars_20mpg.csv")

# convert response column to a factor
cars["economy_20mpg"] <- as.factor(cars["economy_20mpg"])

# set the predictor names and the response column name
predictors <- c("displacement","power","weight","acceleration","year")
response <- "economy_20mpg"

# create a fold column with 5 folds
# randomly assign fold numbers 0 through 4 for each row in the column
fold_numbers <- h2o.kfold_column(cars, nfolds=5)

# rename the column "fold_numbers"
names(fold_numbers) <- "fold_numbers"

# print the fold_assignment column
print(fold_numbers)

# append the fold_numbers column to the cars dataset
cars <- h2o.cbind(cars,fold_numbers)

# try using the fold_column parameter:
cars_gbm <- h2o.gbm(x = predictors, y = response, training_frame = cars,
                    fold_column="fold_numbers", seed = 1234)

# print the auc for your model
print(h2o.auc(cars_gbm, xval = TRUE))
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46296441

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档