【问题标题】:Specify a blocking factor in H2O指定 H2O 中的阻塞因子
【发布时间】:2023-03-30 13:59:02
【问题描述】:

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

我正在处理一个临床数据集,其中包含来自同一患者的多个观察结果,这些观察结果应在这些操作期间保持在一起。

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

谢谢!

【问题讨论】:

  • 这个问题似乎解决了如何在基础 R 中执行此操作:stackoverflow.com/questions/22518982/…
  • 我们已经为此开张了票:0xdata.atlassian.net/browse/PUBDEV-4442 我刚刚将它添加到下一个主要版本的路线图中——希望它会很快实施,但我不能做出任何保证。 (我个人想要这个已经有一段时间了)。
  • 感谢@ErinLeDell。您是否有一个工作示例,说明如何在给定一列 ID 的情况下对 fold_column 进行编码?即,这样的一个例子:The user-specified fold_column method requires the user to code the stratification-by-ID themselves, which is a pain.

标签: r h2o


【解决方案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))

【讨论】:

  • 这很有帮助,谢谢。我希望有一种更通用的方法来做到这一点,无论是否选择了交叉验证(即:可以在h2o.splitFrame() 中指定的东西,这将涵盖一个训练和一个验证集的最简单情况)。跨度>
猜你喜欢
  • 2013-03-29
  • 2023-04-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-03-02
  • 2020-04-30
  • 2014-03-23
相关资源
最近更新 更多