Make Predictions on New Data with a Trained Keras Models

Chris Achard
InstructorChris Achard
Share this video with your friends

Social Share Links

Send Tweet
Published 6 years ago
Updated 5 years ago

Once we choose a network topology and train that network, we will use it to make predictions on new data. At this point, you can now use your network to make predictions on data in production!

Instructor: [00:01] Keras models that have been trained with the fit method can be used to make predictions using the predict method. The only required parameter to predict is the input values. The shapes of those values need to be NumPy arrays that matches the training input data.

[00:19] For this example, that is an array of four numeric values, make a variable called xPredict which would be a NumPy array just like the training in validation data. Then we can add one or more set of inputs that we want to make predictions for.

[00:38] Let's start with just this one. We can supply that to the predict method and assign that to the output variable. The mean of all four inputs, 1.5, 2, 3.5, and 4, is 2.75. We'll print out that we expect to see 2.75, and we'll print the actual value that the network predicts.

[01:05] The value we get is pretty close. In just 100 EPoX, we were able to train the neural net to get close to calculating the mean of four numbers. At least, that is, for inputs that look similar to our trained inputs. Also, notice that the output is actually an array that contains an array that contains the output value.

[01:24] That's because the predict method can take more than one input data at the same time. Let's add a few more and record the expected mean values. When we run that, we see all three outputs come out at the same time which is the reason the outputs are in an array.

[01:49] Finally, the reason that each individual output is an another array is because we could have defined our neural network with more than one output. If we did, we would get all the outputs here, but we just defined a single output, so we only get one numeric value in each output array

egghead
egghead
~ 42 minutes ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today