deep-learning-with-python-notebooks: Training and validation loss plot uses wrong history.history keys

Notebook 3.5-classifying-movie-reviews

The code that is supposed to generate the Training and validation loss side by side uses wrong history.history keys:

acc = history.history['acc'] val_acc = history.history['val_acc'] loss = history.history['loss'] val_loss = history.history['val_loss']

which results in the following errors: KeyError: 'acc' KeyError: 'val_acc'

If you examine de history.history keys you can see that they have different names: history_dict = history.history history_dict.keys()

dict_keys(['loss', 'val_loss', 'binary_accuracy', 'val_binary_accuracy'])

This is probably due to the use of metrics.binary_accuracy as the metric for evaluating the model. The following change in keys would fix the error: acc = history.history['binary_accuracy'] val_acc = history.history['val_binary_accuracy']

About this issue

  • Original URL
  • State: open
  • Created 7 years ago
  • Reactions: 17
  • Comments: 17

Most upvoted comments

Hey, for me it was solved by typing ‘accuracy’ instead of ‘acc’ , I was told that its a keras version mismatch. @techSash @seifmahmoud

Hi. I got the key error when I used history.histroy['acc']. So I changed it to history.history['binary_accuracy'] and even that gives me the same error. I am using tensorflow 2.1.0. history.history.keys() return dict_keys(['loss', 'accuracy']). How do I access val_acc and val_loss

I have the same error, is there a fix for this?

@thisiseshan try ‘accuracy’ instead of ‘binary_accuracy’

It is still open because there are lots of us and new students who are struggling with coding (unlike you). Do not follow the thread if it is a waste of your precious time.

On Sat, Aug 22, 2020 at 10:41 PM Aryan Choudhary notifications@github.com wrote:

LOL it is very simple just use print(history.history) and use the output accordingly, I wonder why this issue is still open.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/fchollet/deep-learning-with-python-notebooks/issues/16#issuecomment-678691700, or unsubscribe https://github.com/notifications/unsubscribe-auth/AGMBYRAUF62QJ4IGIEHCBULSCAUQVANCNFSM4EGXIDFA .