Project - Stock Closing Price Prediction using Deep Learning, TensorFlow2 & Keras

31 / 32

Visualizing Loss vs Epochs

Now that we have built the model, let us visualize how the model loss varies with respect to the epoch for the train data and validation data using matplotlib.

INSTRUCTIONS
  • Firstly, let us have a look at the history, where all the history about various parameters like loss, mean_squared_error, and validation mean_squared_error are stored when the model was fit on train data and validated on validation data.

    print(history.history.keys())
    
  • Since we aim to plot the training loss an validation loss behavior with respect to the number of epochs, let us use those corresponding values from history.history dictionary.

    loss represents the training loss and val_loss indicates the validation loss.

    Let us plot the training loss and validation loss. We shall also set the title, ylabel, xlabel, and legend for the plot and finally show it.

    plt.plot(history.history['loss'])  # plotting train loss
    plt.plot(<< your code comes here >>)  # plotting validation loss
    
    plt.title('model loss')
    plt.ylabel('loss')
    plt.xlabel('epoch')
    plt.legend(['train', 'val'], loc='upper left')
    plt.show()
    
Get Hint See Answer


Note - Having trouble with the assessment engine? Follow the steps listed here

Loading comments...