官术网_书友最值得收藏!

  • R Deep Learning Cookbook
  • Dr. PKS Prakash Achyutuni Sri Krishna Rao
  • 247字
  • 2021-07-02 20:49:15

How to do it...

The section will focus on optimizing hyper parameters in H2O using grid searches.

  1. In our case, we will optimize for the activation function, the number of hidden layers (along with the number of neurons in each layer), epochs, and regularization lambda (l1 and l2):
# Perform hyper parameter tuning
activation_opt <- c("Rectifier","RectifierWithDropout", "Maxout","MaxoutWithDropout")
hidden_opt <- list(5, c(5,5))
epoch_opt <- c(10,50,100)
l1_opt <- c(0,1e-3,1e-4)
l2_opt <- c(0,1e-3,1e-4)

hyper_params <- list(activation = activation_opt,
hidden = hidden_opt,
epochs = epoch_opt,
l1 = l1_opt,
l2 = l2_opt)
  1. The following search criteria have been set to perform a grid search. Adding to the following list, one can also specify the type of stopping metric, the minimum tolerance for stopping, and the maximum number of rounds for stopping:
#set search criteria
search_criteria <- list(strategy = "RandomDiscrete", max_models=300)
  1. Now, let's perform a grid search on the training data as follows:
# Perform grid search on training data
dl_grid <- h2o.grid(x = x,
y = y,
algorithm = "deeplearning",
grid_id = "deep_learn",
hyper_params = hyper_params,
search_criteria = search_criteria,
training_frame = occupancy_train.hex,
nfolds = 5)
  1. Once the grid search is complete (here, there are 216 different models), the best model can be selected based on multiple metrics such as logloss, residual deviance, mean squared error, AUC, accuracy, precision, recall, f1, and so on. In our scenario, let's select the best model with the highest AUC:
#Select best model based on auc
d_grid <- h2o.getGrid("deep_learn",sort_by = "auc", decreasing = T)
best_dl_model <- h2o.getModel(d_grid@model_ids[[1]])
主站蜘蛛池模板: 阜阳市| 凉城县| 威海市| 吴忠市| 万安县| 丁青县| 阜新市| 大足县| 咸阳市| 汾西县| 阜城县| 赤峰市| 常宁市| 罗江县| 贺州市| 荥经县| 青铜峡市| 石首市| 炉霍县| 揭阳市| 贡觉县| 淅川县| 黎川县| 长丰县| 长宁区| 乌审旗| 留坝县| 府谷县| 东兴市| 镇巴县| 铜山县| 岐山县| 乌兰察布市| 邳州市| 永善县| 盐城市| 若尔盖县| 固镇县| 临高县| 新巴尔虎左旗| 惠水县|