-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathH2O_grid.R
More file actions
39 lines (26 loc) · 777 Bytes
/
H2O_grid.R
File metadata and controls
39 lines (26 loc) · 777 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
rm(list = ls())
library(datasets)
data(iris)
summary(iris)
library(h2o)
h2o.init(nthreads = -1, max_mem_size = "4G")
iris.hex <- as.h2o(iris)
ntrees_opts <- c(1, 5)
learn_rate_opts <- c(0.1, 0.01)
hyper_parameters <- list(ntrees = ntrees_opts, learn_rate = learn_rate_opts)
grid_id<-"gbm_grid_test"
grid <- h2o.grid("gbm", grid_id=grid_id, x=1:4, y=5, training_frame=iris.hex, hyper_params = hyper_parameters)
summary(grid)
model_ids <- grid@model_ids
grid_models <- lapply(grid@model_ids, function(mid) {
model = h2o.getModel(mid)
})
print(grid_models)
stopping_metric <- 'accuracy'
sorted_models <- h2o.getGrid(
grid_id = grid_id,
sort_by = stopping_metric,
decreasing = TRUE
)
best_model <- h2o.getModel(sorted_models@model_ids[[1]])
print(best_model)