Keras: In training process, validation data are necessary?

Created on 12 Apr 2016  路  3Comments  路  Source: keras-team/keras

1銆両n training process, validation data are necessary? According to my experiments, training loss is also decreasing and training accuracy is also visible without validation data (I use model.fit()). So I think validation data are not necessary. The positions of validation_X,validation_Y could be assigned to test data. Am I wrong?

hist = model.fit(train,train_label, batch_size=32, nb_epoch=10, verbose=1, show_accuracy=True, validation_data=(test, test_label))
print (max(hist.history['val_acc']))

2銆両n fit() function, how can I get the best model among the total epoches?
Any opinions would be appreciated!

Most helpful comment

You have to use a validation set. More or less by definition, the best model is the one which generalizes best, i.e. performs best on unseen data.

All 3 comments

  1. You don't have to use validation data during training. Training loss/accuracy are evaluated on the training set (with which you train the model), whereas validation loss/accuracy are calculated based on the provided validation set. Therefore, training loss/accuracy are of course not affected if you don't use validation data. The main two reasons why to use a validation set is to perform model selection and to detect overfitting, see also here: https://en.wikipedia.org/wiki/Test_set#Validation_set.
  2. You can e.g. use a model checkpoint callback with save_best_only=True

@rpinsler Thanks for your reply! I have read the checkpoint function. I find that monitor must be 'val_loss' or 'val_acc'. Therefore, it is necessary to set validation data to get the best model. If I don't want to leverage the validation data, which will make the training samples less, how can I get the best model?

You have to use a validation set. More or less by definition, the best model is the one which generalizes best, i.e. performs best on unseen data.

Was this page helpful?
0 / 5 - 0 ratings