I am new with TensorFlow (Python) and I can not juge my obtained results in terms of training and testing accuracy

I am using the GradientDescentOptimizer with a learning coeff equal to 10^(-4) and I have executed the following code :

for gg  in range (1501):
    session.run(optimizer, feed_dict=train_data)
    train_accuracy = session.run(accuracy, feed_dict=train_data)
    if gg % 100 ==0 :
        session.run(optimizer, feed_dict=test_data)
        test_accuracy = session.run(accuracy, feed_dict=test_data)

One time I have commented the testing accuracy to print only the training accuracy and one time I did the contrary. I had stored them in the following table: The Table I have obtained

My problem is that I am not able to detect overfitting if it exists or not Can you help me please!


Accuracies do not signal a warning as @Simon points out, but you seem to be training your optimizer with the test data at each 100-th iteration, which makes all our conclusions invalid.

i.e. the line session.run(optimizer, feed_dict=test_data)

  • $\begingroup$ Yes, my answer is moot until this has been fixed. Nice catch! :) $\endgroup$ – Simon Larsson Jan 16 at 19:38
  • $\begingroup$ So what should I do? should I reset the program to try each number of iteration seperatly? I did this and I got the same results like the ones given by this program. $\endgroup$ – baddy Jan 17 at 8:10
  • 1
    $\begingroup$ You should remove the line session.run(optimizer, feed_dict=test_data). Even if it's gonna be similar, it's better to do it right. If you obtain a similar table, I personally don't think you've reached overfitting point. $\endgroup$ – gunes Jan 17 at 14:16
  • 1
    $\begingroup$ You will completely remove it, because it tunes your optimizer using the test data. I can't give you an exact number for the iteration but 1500 iterations seems good, if you obtain similar values. Because, the training and test accuracies are close. $\endgroup$ – gunes Jan 17 at 16:21
  • 1
    $\begingroup$ Yes! Only remove the session.run(optimizer, feed_dict=test_data) line and run again. Don't be surprised if you test accuracy end up being lower. Then you can look at my answer to see if it is overfitting or not. $\endgroup$ – Simon Larsson Jan 18 at 7:56

Short answer, no it does not look like you are overfitting. Your validation (you call this test) accuracy seems to follow your training accuracy quite closely.

Easiest way to check for yourself is to plot the training and validation accuracy over each iteration, then look at how the curves behave. What you want to see is a test curve that closely follows your validation curve.

Overfitting can come in too ways, your validation curve being quite a bit lower than your training curve and/or a validation curve that is decreasing when the training curve is increasing.

Both these behaviors can be seen in this picture:

Plot showing both overfitting and no overfitting

Image taken from Stanford's CS231n

Edit: As gunes points out you seem to have a programming error that should be addressed before any checks for overfitting.


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.