1

I am training a model to perform a binary classification through Keras. After my model is trained, I tried evaluate it, like this:

# Evaluate the model
print('Evaluate on test data')
loss, acc = model.evaluate(X_test, y_test, verbose=2)
print('Test loss: %.4f' % loss)
print('Test accuracy: %.4f' % acc)

And I got this result:

Evaluate on test data
116/1 - 0s - loss: 0.3099 - accuracy: 0.8793
Test loss: 0.2802
Test accuracy: 0.8793

My question is, why the loss values reported are different? i.e, 0.3099 and 0.2802? Is this some kind of bug? Or am I missing something here?

frogatto
  • 28,539
  • 11
  • 83
  • 129
Murilo
  • 533
  • 3
  • 15
  • 1
    Isn't `loss = 0.3099` for the last batch of the testing and `Test loss = 0.2802` the best loss on every batch of the test dataset ? – Orphee Faucoz Jan 21 '20 at 11:39

1 Answers1

3

No, its not a bug, it makes sense once you are aware how both numbers are computed. Since you set verbose=2 in your model.evaluate call, it shows the progress of batches over the test set.

The accuracy and loss displayed in the progress bar are a exponentially average over batches, as to ease visualization. The loss and accuracy you get as return from model.evaluate is the total loss/accuracy averaged over batches, and are the numbers you should consider as final and correct.

Dr. Snoopy
  • 55,122
  • 7
  • 121
  • 140