Example #1
0
    param_grid = {
        'epochs': [42],
        'batch_size': [50],
        'optimizer': optimizer_list,
        'n1': [32, 36, 40, 42, 46],
        'n2': [10, 15, 20, 25, 30],
        'activation': activation
    }  #'n1':range(37,40), 'n2':range(20,45,5)}
    grid_search = GridSearchCV(estimator=model,
                               param_grid=param_grid,
                               n_jobs=-1,
                               cv=3,
                               scoring=['accuracy'],
                               verbose=10)
    grid_result = grid_search.fit(X_train, y_train)
    report(grid_result.cv_results_, n_top=10)
    print("GridSearchCV took %.2f seconds." % (time.time() - time1))

random_search = False
if random_search:
    time1 = time.time()
    # specify parameters and distributions to sample from
    param_dist = {
        "optimizer":
        ['SGD', 'RMSprop', 'Adagrad', 'Adadelta', 'Adam', 'Adamax', 'Nadam'],
        "activation":
        ['softmax', 'softplus', 'softsign', 'tanh', 'sigmoid', 'hard_sigmoid'],
        "n1":
        randint(1, 50),
        "n2":
        randint(5, 50),
    # specify parameters and distributions to sample from
    param_dist = {"n1": sp_randint(15, 80),
              "n2": sp_randint(10, 80),
              "n3": sp_randint(10, 80),              
              "epochs": sp_randint(30, 60),
              "batch_size": sp_randint(20, 100),
              "optimizer":['rmsprop', 'nadam', 'adagrad'],
              "activation": ['softmax', 'sigmoid', 'softplus']
              }

    
    n_iter_search = 100
    random_search = RandomizedSearchCV(model, param_distributions = param_dist, n_iter=n_iter_search, cv = 3, scoring=scorer, verbose=10)    
    random_search.fit(X_train, y_train)
    report(random_search.cv_results_)
    #scores = random_search.cv_results_['mean_test_score']
    
    
    
if useGridCV:

    # grid setup
    optimizers = ['adam']
    activations = ['softplus', 'sigmoid'] #['sigmoid', 'softmax', 'softplus']
    #inits = ['glorot_uniform', 'normal', 'uniform']
    epochs = [15] #range(10, 100, 20)
    batches = [33] #range(50, 500, 50)
    n1s = [73, 75, 77]
    n2s = [12, 14, 16]  
    n3s = [14, 16, 18]  #3 x 3 x 3 x 2 = 54