Join egghead, unlock knowledge.

Want more egghead?

This lesson is for members. Join us? Get access to all 3,000+ tutorials + a community with expert developers around the world.

Unlock This Lesson
1×
Become a member
to unlock all features

Level Up!

Access all courses & lessons on egghead today and lock-in your price for life.

Autoplay

    Make Binary Class Predictions with Keras Using predict and predict_classes

    Chris AchardChris Achard
    pythonpython
    ^3.0.0

    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.

    Code

    Code

    Become a Member to view code

    You must be a Member to view code

    Access all courses and lessons, track your progress, gain confidence and expertise.

    Become a Member
    and unlock code for this lesson
    Discuss

    Discuss

    Transcript

    Transcript

    Instructor: 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.

    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.

    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.