0

This link has a tutorial that shows how to plot different metrics for test and training data by epochs. Please check the output of plot_metrics(baseline_history)

I only have two metrics to print I copied the plotting part and need help with below

  1. How to change color of test line to red? I tried plt.plot(history.epoch, history.history['val_'+metric], color=colors['r'], linestyle="--", label='Val') But got the error TypeError: list indices must be integers or slices, not str

  2. how to ensure the plain background. For some reason I am getting grey color background with white lines

my code and output below

#plotting
def plot_metrics(history):
  metrics =  ['loss','acc']
  for n, metric in enumerate(metrics):
    name = metric.replace("_"," ").capitalize()
    plt.subplot(2,2,n+1)
    plt.plot(history.epoch,  history.history[metric], color=colors[0], label='Train')
    plt.plot(history.epoch, history.history['val_'+metric],
             color=colors[9], linestyle="--", label='Val')
    plt.xlabel('Epoch')
    plt.ylabel(name)
    if metric == 'loss':
      plt.ylim([0, plt.ylim()[1]])
    elif metric == 'auc':
      plt.ylim([0.8,1])
    else:
      plt.ylim([0,1])

    plt.legend()

import matplotlib.pyplot as plt
colors = plt.rcParams['axes.prop_cycle'].by_key()['color']

import matplotlib as mpl
mpl.rcParams['figure.figsize'] = (20, 12)
plot_metrics(final_model)#where abcde is fit call

enter image description here

1 Answer 1

1
  1. You can simply try adding the color parameter. Usage: plt.plot([1,2,3,4,5,6], color='red')

  2. You can use grid(False) to remove the grid. usage: plt.grid(False)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.