In [1]:
import h2o
import os.path
from collections import OrderedDict
from builtins import range
from h2o.estimators.deepwater import H2ODeepWaterEstimator
from h2o.grid.grid_search import H2OGridSearch
h2o.init(nthreads=-1)
PATH=os.path.expanduser("~/h2o-3/")
In [7]:
!nvidia-smi
In [2]:
train = h2o.import_file(PATH + "smalldata/iris/iris_wheader.csv")
predictors = list(range(0,4))
response_col = 4
In [3]:
hyper_parameters = {
'hidden' : [[20,20],[50,50,50],[200,200],[50,50,50,50,50]],
'activation' : ["tanh","rectifier"],
'learning_rate' : [lr/1e3 for lr in range(1,10)]
}
parameters = {
'seed' : 42,
'epochs' : 500,
'nfolds' : 3,
'stopping_rounds' : 3, ## enable early stopping of each model in the hyperparameter search
'stopping_metric' : "logloss",
'stopping_tolerance' : 1e-3 ## stop once validation logloss of the cv models doesn't improve enough
}
search_criteria = {
'strategy': "RandomDiscrete",
'max_runtime_secs': 30, ## limit the runtime to 30 seconds
'max_models': 100, ## build no more than 100 models
'seed' : 42,
'stopping_rounds' : 5, ## enable early stopping of the overall leaderboard
'stopping_metric' : "logloss",
'stopping_tolerance': 1e-4
}
print(hyper_parameters)
In [4]:
gs = H2OGridSearch(H2ODeepWaterEstimator,
hyper_params=hyper_parameters,
search_criteria=search_criteria)
gs.train(x=predictors, y=response_col, training_frame=train, **parameters)
In [5]:
gs.get_grid("logloss")
Out[5]: