Make Binary Class Predictions with Keras Using predict and predict_classes

Chris Achard
InstructorChris Achard

Share this video with your friends

Send Tweet
Published 3 years ago
Updated 3 years ago

We will use the Keras model’s predict method to look at the predicted class value. Then we will use the predict_classes method to have Keras make a class prediction for us, and return only a 0 or a 1, which represents the predicted class.

Instructor: [00:01] Our neural network takes in four numerical values and predicts a class of zero, if the values are low, and one, if the values are high. After the neural network is trained, make some inputs to test that are NumPy arrays of four values each. Then, we will call the models predict method to make predictions on those inputs and print the output to the screen.

[00:28] When we run that, we see that the network returns a floating point value and not a class of zero or one like you might expect. What you are seeing is the raw output from the sigmoid function that we defined on the output node and not the classes as we define them.

[00:48] We could round these predicted values to get to a class, or we'd have Keras do that for us by calling the predict classes method instead of just predict. Once we change to that, we see the proper classes for our input data.