使用 h2o 進行隨機搜尋
接下來,你會使用隨機搜尋(random search)。h2o 套件與 seeds_train_data 已為你載入,並且已執行以下程式碼:
h2o.init()
seeds_train_data_hf <- as.h2o(seeds_train_data)
y <- "seed_type"
x <- setdiff(colnames(seeds_train_data_hf), y)
seeds_train_data_hf[, y] <- as.factor(seeds_train_data_hf[, y])
sframe <- h2o.splitFrame(seeds_train_data_hf, seed = 42)
train <- sframe[[1]]
valid <- sframe[[2]]
dl_params <- list(hidden = list(c(50, 50), c(100, 100)),
epochs = c(5, 10, 15),
rate = c(0.001, 0.005, 0.01))
本練習屬於課程
R 的超參數調校
練習說明
- 建立一個搜尋條件(search criteria)物件,定義隨機搜尋,並將最長執行時間設為 10 秒。
- 將這個搜尋條件物件加入
h2o.grid函式中適當的位置,以訓練隨機搜尋的模型。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Define search criteria
search_criteria <- list(strategy = ___,
___ = 10, # this is way too short & only used to keep runtime short!
seed = 42)
# Train with random search
dl_grid <- h2o.grid("deeplearning",
grid_id = "dl_grid",
x = x,
y = y,
training_frame = train,
validation_frame = valid,
seed = 42,
hyper_params = dl_params,
___ = ___)