gpt4 book ai didi

r - R 和 H2O 中的参数优化

转载 作者:行者123 更新时间:2023-11-30 08:43:59 29 4
gpt4 key购买 nike

我需要对RH2o上的gbm模型进行参数优化。我对 H2o 比较陌生,我认为在执行以下操作之前我需要将 ntrees 和 learn_rate(如下)转换为 H2o 向量。我该如何执行此操作?谢谢!

ntrees <- c(100,200,300,400)
learn_rate <- c(1,0.5,0.1)
for (i in ntrees){
for j in learn_rate{
n = ntrees[i]
l= learn_rate[j]
gbm_model <- h2o.gbm(features, label, training_frame = train, validation_frame = valid, ntrees=ntrees[[i]],max_depth = 5,learn_rate=learn_rate[j])
print(c(ntrees[i],learn_rate[j],h2o.mse(h2o.performance(gbm_model, valid = TRUE))))

}
}

最佳答案

您可以使用h2o.grid()进行网格搜索

# specify your hyper parameters
hyper_params = list( ntrees = c(100,200,300,400), learn_rate = c(1,0.5,0.1) )

# then build your grid
grid <- h2o.grid(
## hyper parameters
hyper_params = hyper_params,

## which algorithm to run
algorithm = "gbm",

## identifier for the grid, to later retrieve it
grid_id = "my_grid",

## standard model parameters
x = features,
y = label,
training_frame = train,
validation_frame = valid,

## set a seed for reproducibility
seed = 1234)

您可以在 R 文档 http://docs.h2o.ai/h2o/latest-stable/h2o-r/h2o_package.pdf 中阅读有关 h2o.grid() 如何工作的更多信息

关于r - R 和 H2O 中的参数优化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40006311/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com