- 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]])
推薦閱讀
- DB2 V9權(quán)威指南
- Learning ArcGIS Pro 2
- C# 從入門到項目實踐(超值版)
- Java Web及其框架技術(shù)
- Servlet/JSP深入詳解
- Django Design Patterns and Best Practices
- UML+OOPC嵌入式C語言開發(fā)精講
- 琢石成器:Windows環(huán)境下32位匯編語言程序設(shè)計
- ArcGIS By Example
- 快人一步:系統(tǒng)性能提高之道
- MATLAB for Machine Learning
- Internet of Things with ESP8266
- Python入門很輕松(微課超值版)
- 零基礎(chǔ)學(xué)Python編程(少兒趣味版)
- HTML5+CSS3+jQuery Mobile APP與移動網(wǎng)站設(shè)計從入門到精通