The history callback
The history callback is returned by default every time you train a model with the .fit()
method. To access these metrics you can access the history
dictionary parameter inside the returned h_callback
object with the corresponding keys.
The irrigation machine model
you built in the previous lesson is loaded for you to train, along with its features and labels now loaded as X_train
, y_train
, X_test
, y_test
.
This time you will store the model's history
callback and use the validation_data
parameter as it trains.
You will plot the results stored in history
with plot_accuracy()
and plot_loss()
, two simple matplotlib functions.
You can check their code in the console by pasting show_code(plot_loss)
.
Let's see the behind the scenes of our training!
This exercise is part of the course
Introduction to Deep Learning with Keras
Exercise instructions
- Train your model on
X_train
andy_train
, validate each epoch onX_test
andy_test
. - Use
plot_loss
extractingloss
andval_loss
fromh_callback
. - Use
plot_accuracy
extractingaccuracy
andval_accuracy
fromh_callback
.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Train your model and save its history
h_callback = ____.____(____, ____, epochs = 25,
validation_data=(____, ____))
# Plot train vs test loss during training
plot_loss(h_callback.history[____], h_callback.history[____])
# Plot train vs test accuracy during training
plot_accuracy(h_callback.history[____], h_callback.history[____])