-1
$\begingroup$

The problem that I'm facing is that the training accuracy of my model is way higher than the validation accuracy, were talking about an approximate value of 0.2. And I can't understand why, yet I'm still a newbie when it comes to this so bear with me, please.

The data comes from two datasets which were created using f.data.Dataset, one for training another for validation since that's how the dataset had his folder layout.

model = keras.Sequential([
    keras.layers.Flatten(),
    keras.layers.Dense(256, activation='relu'),
    keras.layers.Dropout(.1),
    keras.layers.Dense(2, activation="softmax")
])

model.compile(optimizer='adam',
            loss="categorical_crossentropy",
            metrics=['accuracy'])

model.fit(train_ds, steps_per_epoch=STEPS_PER_EPOCH, epochs=10, validation_data=test_ds, validation_steps=VALIDATION_STEPS)
Train for 163.0 steps, validate for 20.0 steps
Epoch 1/10
163/163 [==============================] - 3s 21ms/step - loss: 3.9965 - accuracy: 0.8468 - val_loss: 0.3582 - val_accuracy: 0.8406
Epoch 2/10
163/163 [==============================] - 3s 19ms/step - loss: 0.3197 - accuracy: 0.8930 - val_loss: 0.5207 - val_accuracy: 0.7641
Epoch 3/10
163/163 [==============================] - 3s 19ms/step - loss: 0.2009 - accuracy: 0.9191 - val_loss: 0.4350 - val_accuracy: 0.8062
Epoch 4/10
163/163 [==============================] - 3s 19ms/step - loss: 0.1815 - accuracy: 0.9270 - val_loss: 0.5521 - val_accuracy: 0.7516
Epoch 5/10
163/163 [==============================] - 3s 19ms/step - loss: 0.2122 - accuracy: 0.8986 - val_loss: 0.9616 - val_accuracy: 0.7156
Epoch 6/10
163/163 [==============================] - 3s 19ms/step - loss: 0.2405 - accuracy: 0.9082 - val_loss: 1.2039 - val_accuracy: 0.7109
Epoch 7/10
163/163 [==============================] - 3s 19ms/step - loss: 0.2013 - accuracy: 0.9183 - val_loss: 0.7242 - val_accuracy: 0.6406
Epoch 8/10
163/163 [==============================] - 3s 19ms/step - loss: 0.2055 - accuracy: 0.9176 - val_loss: 0.4830 - val_accuracy: 0.6891
Epoch 9/10
163/163 [==============================] - 3s 19ms/step - loss: 0.1901 - accuracy: 0.9250 - val_loss: 0.3925 - val_accuracy: 0.8313
Epoch 10/10
163/163 [==============================] - 3s 19ms/step - loss: 0.1861 - accuracy: 0.9202 - val_loss: 0.5492 - val_accuracy: 0.8000

Could anyone explain to me please what could cause this big gap in between accuracy and val_accuracy, please?

$\endgroup$
1
$\begingroup$

Your model is clearly overfitting. You should use higher dropout value like 0.5 .For better generalization use deep models. And you can also use early stopping so that your model stops training before significantly overfitting.

| improve this answer | |
$\endgroup$
  • $\begingroup$ I gave it a run with a dropout of 0.5 and early stop patience of 3 now the accuracy dropped significantly, from approx. 95 to 80. do you have any idea why? $\endgroup$ – Terchila Marian Jul 1 at 11:24
  • 1
    $\begingroup$ Yes train accuracy will surely decrease. Training a model is not all about gaining higher accuracy in train set but in validation set. So train your model as long as your validation score increases. Or otherwise use different data augmentation , regularizer technique to improve both train and val score. $\endgroup$ – SrJ Jul 1 at 11:27
  • $\begingroup$ I know this might appeal silly to you, but I'm still a newbie when it comes to this. by suggesting to keep training are you referring to increasing the number of epochs? $\endgroup$ – Terchila Marian Jul 1 at 11:29
  • 1
    $\begingroup$ Yes i am referring to give as many epoch as possible until your val score stop to increase $\endgroup$ – SrJ Jul 1 at 11:31

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.