neural network hyperparameter tuning

Solutions on MaxInterview for neural network hyperparameter tuning by the best coders in the world

showing results for - "neural network hyperparameter tuning"
Mateo
21 Jan 2020
1# random search cross validation in neural network model
2
3from keras.models import Sequential
4from keras.layers import Dense, Dropout
5from keras.wrappers.scikit_learn import KerasClassifier
6
7def report(results, n_top=3):
8    for i in range(1, n_top + 1):
9        candidates = numpy.flatnonzero(results['rank_test_score'] == i)
10        for candidate in candidates:
11            print("Model with rank: {0}".format(i))
12            print("Mean validation score: {0:.3f} (std: {1:.3f})"
13                  .format(results['mean_test_score'][candidate],
14                          results['std_test_score'][candidate]))
15            print("Parameters: {0}".format(results['params'][candidate]))
16            print("")
17
18def nn_model(activation = 'relu', neurons = 32, optimizer = 'Adam',dropout = 0.1, init_mode = 'uniform'):
19    model = Sequential()
20    model.add(Dense(32, input_dim = 32, kernel_initializer = init_mode, activation= activation))
21    model.add(Dense((neurons*2)//3, kernel_initializer = init_mode,activation= activation))
22    model.add(Dense((neurons*4)//9,kernel_initializer = init_mode,  activation = activation))
23    model.add(Dropout(dropout))
24    model.add(Dense(1, kernel_initializer = init_mode, activation='sigmoid'))
25    model.compile(loss='binary_crossentropy', optimizer= optimizer, metrics=['accuracy'])
26    return model
27
28# Defining grid parameters
29activation = ['softmax', 'softplus', 'softsign', 'relu', 'selu', 'elu', 'tanh','sigmoid', 'linear']
30neurons = range(31,39)
31dropout = [0.0, 0.1, 0.2, 0.3, 0.4, 0.5]
32init_mode = ['uniform', 'lecun_uniform', 'normal', 'zero', 'glorot_normal', 'glorot_uniform', 'he_normal', 'he_uniform']
33optimizer = ['SGD', 'Adam', 'Adamax','RMSprop','Adagrad','Adadelta','Nadam','Ftrl']
34batch_size = range(10,101,10)
35param_grid = dict(activation = activation, neurons = neurons, optimizer = optimizer, dropout = dropout, init_mode = init_mode, batch_size = batch_size)
36
37clf = KerasClassifier(build_fn= nn_model, epochs= 10, verbose= 1)
38
39model = RandomizedSearchCV(estimator= clf, param_distributions = param_grid, n_jobs=-1,verbose = 3)
40model.fit(stan_x_train,stan_y_train)
41
42report(model.cv_results_)
queries leading to this page
how important is hyperparameter tuning in machine learningwhat algorithms used for hyperparameters tuning neural networkhyperparameter tuning deep learningneural network hyperparameter tuninghyperparameter tuning machine learning hyperparameter optimization neural network in kerasdeep learning hyperparameter tuninghyperparameter tuning with mlrwhat are hyperparameters in neural networkhyperparameter tuning neural network keraswhat are hyperparameters in neural networkshyperparameter tuning function for neural network pythonwhat is hyperparameter tuning in machine learningml hyperparameter tuningwhat are hyperparameter tuning in machine learninghyperparameter of a neural networkhyperparameter tuning using random search in neural networkneural network parameters and hyperparametershyperparameter tuning for machine learninghyperparameter tuning neural network pythonhyperparamters neural networkhow to choose hyperparameters for neural networkhyperparameter tuning for deep learningml hyperparameters tuning packagehyperparameter tuning in cnn examplemachine learning hyperparameter tuningneural network hyperparameter optimization pythonfine tuning hyperparameter of the ml modelhyperparameter optimization neural networkml model hyperparameters tuninghyperparameter tuning artificial neural network classification codehyperparameter tuning in machine learninghyperparameters of neural networkhyperparameters in neural networkusing a neural networks to tuning hyperparameterscikit learn neural network hyperparameter tuninghyperparameter neural networkhyperparameter tuning convolutional neural networkbasic hyperparameters of neural networkhyperparameters in neural networksneural network step hyperparametershyperparameter in a neural networksupervised machine learning with hyperparameter tuninghyperparameter tuning in deep learningcnn hyperparameter tuning kagglewhat are hyperparameters of a neural networkthe hyperparameters in a neural network arecompute hyperparameter tuning neural networkhyperparameters neural networkhyperparameters for neural networkneural network hyperparametershyperparameter tuning neual network machine learning masterywhat is hyperparameter in neural networkhyperparameters tuning in machine learningneural networks hyperparametersneural network hyperparameter tuning