1

I am building a MLP using TensorFlow 2.0. I am plotting the learning curve and also using keras.evaluate on both training and test data to see how well it performed. The code I'm using:

history = model.fit(X_train, y_train, batch_size=32, epochs=200, validation_split=0.2, verbose=0) # evaluate the model eval_result_tr = model.evaluate(X_train, y_train) eval_result_te = model.evaluate(X_test, y_test) print("[training loss, training accuracy]:", eval_result_tr) print("[test loss, test accuracy]:", eval_result_te) #[training loss, training accuracy]: [0.5734676122665405, 0.9770742654800415] #[test loss, test accuracy]: [0.7273344397544861, 0.9563318490982056] #plot the learning rate curve import matplotlib.pyplot as plt plt.plot(history.history["loss"], label='eğitim') plt.plot(history.history['val_loss'], label='doğrulama') plt.xlabel("Öğrenme ivmesi") plt.ylabel("Hata payı") plt.title("Temel modelin öğrenme eğrisi") plt.legend() 

The output is:

The output:

My question is: How keras.evaluate() calculates the training loss to be 0.5734676122665405? I take the average of history.history["loss"] bu it returns different (0.7975356701016426) value.

Or, am I mistaken to begin with by trying to evaluate the model performance on training data by eval_result_tr = model.evaluate(X_train, y_train)?

3
  • Regularization techniques like dropout are usually only active during training. That could be one of the reasons for the differences. Commented Apr 21, 2022 at 9:45
  • 1
    This has been asked many times before, the loss you see is with changing weights during training, evaluating outside of training will use fixed weights, so you will always see a different loss value. Please search the site before asking. Commented Apr 21, 2022 at 9:46
  • I actually searched the site and found similar posts but were not exactly the same issue) and none of them clarify the answer as you did. Thank you. Commented Apr 22, 2022 at 8:01

1 Answer 1

1

For community benefit, adding @Dr. Snoopy's answer here in the answer section.

This has been asked many times before, the loss you see is with changing weights during training, evaluating outside of training will use fixed weights, so you will always see a different loss value.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.