Get startedGet started for free

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 historycallback 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

View Course

Exercise instructions

  • Train your model on X_train and y_train, validate each epoch on X_test and y_test.
  • Use plot_lossextracting lossand val_loss from h_callback.
  • Use plot_accuracyextracting accuracyand val_accuracy from h_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[____])
Edit and Run Code