Evaluate a Keras Model with Test Data

Chris Achard
InstructorChris Achard
Share this video with your friends

Social Share Links

Send Tweet

Once we have a model with good training and validation accuracy, we will create some test data and evaluate the model’s accuracy on the new data set using the evaluate method on the Keras model.

Instructor: [00:01] Make another set of data called X Test and Y Test. This data will be used to test the neural network after training is fully complete. The format should match the train and validation data sets.

[00:13] In this case, there is four input numbers per line in a single output value, which is the correct answer for what we're asking the neural network to predict. For this example case, it's the mean of the four inputs.

[00:27] We can evaluate the loss of our trained network by calling the evaluate method on the model and passing in the x- and the y-values that we just created. The output will be an array of one or more numbers, which represents the metrics that we told our neural network to optimize for.

[00:43] We can print those metric names by calling them Metric Names Method on the model and then print the output to see the actual values. When we run that, we see the hundred epochs like normal with our training loss and validation loss.

[01:01] We also see a single run with the three-new test data points. Finally, we see that our metric is loss. This value represents the loss on the as yet unseen data, which is the test set that we created.

[01:17] In a well-trained and well-tuned, neural network, the training loss, validation loss, and test loss should be similar, which means there is on under or overfitting issues. Also, notice that we've only checked the test set after we fully trained the network.

[01:31] It's a best practice to reserve the test set until the very end of training and validation. Otherwise, it isn't as effective at telling you the actual performance of your network on future unseen data.