我需要对RH2o上的gbm模型进行参数优化。我对H2o比较陌生,我认为在执行下面的操作之前,我需要将ntree和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))))
}
}发布于 2016-10-12 23:30:09
您可以使用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)您可以阅读更多关于h2o.grid()如何在R文档package.pdf中工作的内容。
https://stackoverflow.com/questions/40006311
复制相似问题