Explore Courses Blog Tutorials Interview Questions
0 votes
in Data Science by (17.6k points)

I am a bit confused on how Keras fits the models. In general, Keras models are fitted by simply using something like the following:, y_train, epochs=300, batch_size=64, validation_data=(X_test, y_test))

My question is: Because I stated the testing data by the argument validation_data=(X_test, y_test), does it mean that each epoch is independent? In other words, I understand that at each epoch, Keras train the model using the training data (after getting shuffled) followed by testing the trained model using the provided validation_data. If that's the case, then no matter how many epochs I choose, I only take the results of the last epoch!!

If this scenario is correct, so we do we need multiple epoches? Unless these epoches are dependent somwhow where each epoch uses the same NN weights from the previous epoch, correct?

Thank you

1 Answer

0 votes
by (41.4k points)

1.At each epoch, keras passes through the entire dataset corresponding to the batch_size after it gets fit into your model.

2.Then, on your validation set, the model will do a prediction at the end of each epoch.

3.One epoch would mean that weight is updated only once per element. But we need to minimize the error values or loss function so that we can get the optimal result. So, for this we need multiple epochs, and multiple epochs will pass through the entire dataset multiple times and each time the weight is updated. 

For example, if you have a dataset of 50000 items and a batch_size of 5, the weight of your model will be updated by using 5 items and this will go until it has gone through the entire dataset.

This is how keras fits the model via epochs.

If you wish to learn more about how to use python for data science, then go through data science python programming course by Intellipaat for more insights.

Browse Categories