Skip to content

Instantly share code, notes, and snippets.

@esmitt
Last active October 15, 2020 20:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save esmitt/602f03553781dbb97317d66bbd7a7782 to your computer and use it in GitHub Desktop.
Save esmitt/602f03553781dbb97317d66bbd7a7782 to your computer and use it in GitHub Desktop.
Plotting the loss function using a log scale using Matplotlib
import matplotlib.pyplot as plt
from matplotlib import rcParams
rcParams['figure.figsize'] = (12, 10)
colors = plt.rcParams['axes.prop_cycle'].by_key()['color']
def plot_log_loss(history: History, title_label: str, n: int) -> ():
# Use a log scale to show the wide range of values.
plt.semilogy(history.epoch, history.history['loss'],
color=colors[n], label='Train '+title_label)
plt.semilogy(history.epoch, history.history['val_loss'],
color=colors[n], label='Val '+title_label,
linestyle="--")
plt.xlabel('Epoch')
plt.ylabel('Loss')
plt.legend()
plot_log_loss(history, "Model Base", 1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment