5
$\begingroup$

I'm using two different functions to calculate the accuracy of my deep learning model and I am confused which one is which.

The first one is

    loss, accuracy = model.evaluate(x_train, y_train, verbose=0)
    print('Accuracy: %f' % (accuracy))
    print('Loss: %f' % (loss))

    Accuracy: 0.731495
    Loss: 1.136258

And the second way is to obtain the accuracy:

test_accuracy = history2.history['val_acc']

Accuracy is 0.731 and test_accuracy is around 0.21 Which is one is my models' accuracy

$\endgroup$
  • 4
    $\begingroup$ That's interesting, you are performing badly on your training set(underfitting probably) and so bad on your test set, .731 is for those set of data for which you know the answer already, and the second no is for the unknown test data $\endgroup$ – Aditya May 31 '18 at 12:30
  • $\begingroup$ Should be as Adtiya said, try loss, accuracy = model.evaluate(x_test , y_test verbose=0) and print again. Accuracy should be the same as history2.history['val_acc'] $\endgroup$ – nsaura Sep 3 '18 at 11:06
1
$\begingroup$

The accuracy given by Keras is the training accuracy. This is not a proper measure of the performance of your classifier, as it is not fair to measure accuracy with the data that has been fed to the NN. On the other hand, the test accuracy is a more fair measure of the real performance. As there is a big gap between them, you are overfitting very badly, and you should regularize your model. Consider using dropout or weight decay.

| improve this answer | |
$\endgroup$
  • $\begingroup$ Why overfitting? It can be the case of sheer underfitting too $\endgroup$ – Aditya May 31 '18 at 15:13
1
$\begingroup$
test_accuracy = history2.history['val_acc']

shows your model's accuracy.

| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.