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

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]])
主站蜘蛛池模板: 博乐市| 马边| 庄浪县| 班戈县| 安吉县| 洞口县| 许昌市| 衡阳市| 泰宁县| 民和| 晋州市| 龙门县| 周宁县| 寿阳县| 清河县| 宜章县| 延寿县| 阿克苏市| 平果县| 辽中县| 洛隆县| 潍坊市| 松桃| 进贤县| 恩施市| 德江县| 庄浪县| 蓝田县| 包头市| 怀远县| 南昌县| 东阳市| 响水县| 连州市| 龙陵县| 神木县| 龙山县| 郴州市| 沅陵县| 临清市| 屏南县|