What is the relation between validation_data and validation_split in Keras' fit function?

Viewed 14200

validation_split says: "hey give me all the input data – I will take care of splitting between test and validation".

model.fit(inputX, inputY, validation_split=0.20, epochs=10, batch_size=10)

validation_data says "please give me explicitly the validation data"

model.fit(inputX, inputY, validation_data=(testX,testY), epochs=10, batch_size=10)

Is there any hidden trick or something I am missing apart from my understanding?

4 Answers

Your understanding is correct. To add more details - validation_split keras function makes easy for the user to split the training dataset into train and validation (saving your custom efforts).

For example - setting validation_split=0.2, tells keras to use last 20% of the data before shuffling for validation.

I will just add something important when dealing with unbalanced datasets. Using validation_split does not preserve the percentage of each class. Often, you will do your own validation_data so you keep those percentages. Moreover, I would recommend StratifiedShuffleSplit to do so.

If you use validation_data option, you need to prepare the validataion data and train data seperately, which would take more energy to do. Afterwards, the validation_split option allows you to merely input whole bunch of data and split it inside. Somehow, it is better to save time.

Related