在R版本的H2O中,在训练/验证/测试集中拆分数据和/或进行交叉验证时,是否可以指定阻塞因子?
我正在处理一个临床数据集,其中包含来自同一患者的多个观察数据,这些数据应该在这些手术过程中保存在一起。
如果在H2O框架中不能做到这一点,那么关于如何在R中实现这一点并与H2O函数集成的建议将是很棒的。
谢谢!
发布于 2017-09-19 22:26:14
当使用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))https://stackoverflow.com/questions/46296441
复制相似问题