Search code examples
kerasloss-function

Why in model.evaluate() from Keras the loss is used to calculate accuracy?


It may be a stupid question but:

I noticed that the choice of the loss function modifies the accuracy obtained during evaluation.

I thought that the loss was used only during training and of course from it depends the goodness of the model in making prediction but not the accuracy i.e amount of right predictions over the total number of samples.

EDIT

I didn't explain my self correctly.

My question comes because I recently trained a model with binary_crossentropy loss and the accuracy coming from model.evaluate() was 96%. But it wasn't correct! I checked "manually" and the model was getting 44% of the total predictions. Then I changed to categorical_crossentropy and then the accuracy was correct.

MAYBE ANSWER From: another question

I have found the problem. metrics=['accuracy'] calculates accuracy automatically from cost function. So using binary_crossentropy shows binary accuracy, not categorical accuracy. Using categorical_crossentropy automatically switches to categorical accuracy and now it is the same as calculated manually using model1.predict().


Solution

  • From: another question

    I have found the problem. metrics=['accuracy'] calculates accuracy automatically from cost function. So using binary_crossentropy shows binary accuracy, not categorical accuracy. Using categorical_crossentropy automatically switches to categorical accuracy and now it is the same as calculated manually using model1.predict().