Model Evaluate in Keras

Question:

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?

Asked By: Murilo

||

Answers:

No, it’s 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.

Answered By: Dr. Snoopy
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.