在R版本的H2O中,是否可以在训练/验证/测试集中分割数据和/或进行交叉验证时指定阻塞因子?
我正在研究一个临床数据集,其中有来自同一患者的多个观察结果,应该在这些手术中保持在一起。
如果在H2O框架内无法做到这一点,那么关于如何在R中实现这一点以及与H2O功能集成的建议将会很棒。
谢谢!
答案 0 :(得分:1)
当使用H2O-3进行交叉验证时,您可以使用fold_column
参数告知训练算法观察所属的折叠编号。参见:
下面的代码示例(从上面的链接复制)显示随机分配的折叠。但是你可以交替编写一段代码来自己分配它们。
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))