Last active
April 11, 2019 04:53
-
-
Save crawftv/830d3e48a443df23eec1a249b23adb15 to your computer and use it in GitHub Desktop.
Skopt Tutorial - Fitness Function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@use_named_args(dimensions=dimensions) | |
def fitness(learning_rate, num_dense_layers, num_input_nodes, | |
num_dense_nodes,activation, batch_size,adam_decay): | |
model = create_model(learning_rate=learning_rate, | |
num_dense_layers=num_dense_layers, | |
num_input_nodes=num_input_nodes, | |
num_dense_nodes=num_dense_nodes, | |
activation=activation, | |
adam_decay=adam_decay | |
) | |
#named blackbox becuase it represents the structure | |
blackbox = model.fit(x=X_train, | |
y=y_train, | |
epochs=3, | |
batch_size=batch_size, | |
validation_split=0.15, | |
) | |
#return the validation accuracy for the last epoch. | |
accuracy = blackbox.history['val_acc'][-1] | |
# Print the classification accuracy. | |
print() | |
print("Accuracy: {0:.2%}".format(accuracy)) | |
print() | |
# Delete the Keras model with these hyper-parameters from memory. | |
del model | |
# Clear the Keras session, otherwise it will keep adding new | |
# models to the same TensorFlow graph each time we create | |
# a model with a different set of hyper-parameters. | |
K.clear_session() | |
tensorflow.reset_default_graph() | |
# the optimizer aims for the lowest score, so we return our negative accuracy | |
return -accuracy |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment