Plotting learning curve in keras gives KeyError: 'val_acc'

前端 未结 8 2062
情话喂你
情话喂你 2020-12-09 09:54

I was trying to plot train and test learning curve in keras, however, the following code produces KeyError: \'val_acc error.

The official document

8条回答
  •  青春惊慌失措
    2020-12-09 10:30

    The main point everyone misses to mention is that this Key Error is related to the naming of metrics during model.compile(...). You need to be consistent with the way you name your accuracy metric inside model.compile(....,metrics=['']). Your history callback object will receive the dictionary containing key-value pairs as defined in metrics.

    So, if your metric is metrics=['acc'], you can access them in history object with history.history['acc'] but if you define metric as metrics=['accuracy'], you need to change to history.history['accuracy'] to access the value, in order to avoid Key Error. I hope it helps.

    N.B. Here's a link to the metrics you can use in Keras.

提交回复
热议问题