- 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.
- 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)
- 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)
- 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)
- 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]])
推薦閱讀
- Vue.js 3.x快速入門
- Java面向?qū)ο笏枷肱c程序設(shè)計
- JavaScript:Functional Programming for JavaScript Developers
- Flink SQL與DataStream入門、進(jìn)階與實戰(zhàn)
- Instant Zepto.js
- Windows Presentation Foundation Development Cookbook
- Python深度學(xué)習(xí):基于TensorFlow
- Active Directory with PowerShell
- C語言程序設(shè)計與應(yīng)用(第2版)
- BeagleBone Robotic Projects(Second Edition)
- Illustrator CS6設(shè)計與應(yīng)用任務(wù)教程
- OpenCV 3計算機(jī)視覺:Python語言實現(xiàn)(原書第2版)
- Python+Office:輕松實現(xiàn)Python辦公自動化
- Application Development with Parse using iOS SDK
- ASP.NET Core 2 High Performance(Second Edition)