# How can I know if my NN TensorFlow model is overfitted or not?

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 :
#print(train_accuracy)
session.run(optimizer, feed_dict=test_data)
test_accuracy = session.run(accuracy, feed_dict=test_data)
print(test_accuracy)


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:

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)

• Yes, my answer is moot until this has been fixed. Nice catch! :) – Simon Larsson Jan 16 at 19:38
• 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. – baddy Jan 17 at 8:10
• 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. – gunes Jan 17 at 14:16
• 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. – gunes Jan 17 at 16:21
• 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. – 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:

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.