Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save sethbunke/8d5d3f03777671034bda17a8322cec02 to your computer and use it in GitHub Desktop.
Save sethbunke/8d5d3f03777671034bda17a8322cec02 to your computer and use it in GitHub Desktop.
Keras show training and validation loss over time
from keras.models import Model
import matplotlib.pyplot as plt
history_object = model.fit_generator(train_generator, samples_per_epoch =
len(train_samples), validation_data =
validation_generator,
nb_val_samples = len(validation_samples),
nb_epoch=5, verbose=1)
### print the keys contained in the history object
print(history_object.history.keys())
### plot the training and validation loss for each epoch
plt.plot(history_object.history['loss'])
plt.plot(history_object.history['val_loss'])
plt.title('model mean squared error loss')
plt.ylabel('mean squared error loss')
plt.xlabel('epoch')
plt.legend(['training set', 'validation set'], loc='upper right')
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment