WalzoneInterview Prep
📞 Interviewing soon? Practice with a realistic AI mock phone interview — it calls you, then scores you. First 15 min FREE →

Keras · Basic · question 13 of 100

How do you use the predict() function in Keras, and what does it return?

📕 Buy this interview preparation book: 100 Keras questions & answers — PDF + EPUB for $5

The ‘predict()‘ function in Keras is used to obtain predictions from a trained neural network model. Specifically, given a set of inputs, it will produce a set of output predictions.

Here is an example of how to use ‘predict()‘:

# Load the model from disk
model = load_model('my_model.h5')

# Generate some input data (e.g. test data)
X_test = generate_test_data()

# Use the predict function to obtain output predictions for the input data
y_pred = model.predict(X_test)

Here, we first load the trained model from disk using the ‘load_model()‘ function in Keras. We then generate some test data as input for the model using a hypothetical function ‘generate_test_data()‘. Finally, we use the ‘predict()‘ function to obtain output predictions for our test data, which are stored in ‘y_pred‘.

The ‘predict()‘ function returns a numpy array of predicted outputs for the given input data. The array will have a shape that depends on the number of input samples and the number of output units in the model. For example, if our model had a single output unit, the output array would be a one-dimensional numpy array with a length equal to the number of input samples. If our model had multiple output units, the output array would be a two-dimensional numpy array with dimensions of [number of input samples, number of output units].

Reading is step one. Saying it out loud is the interview. Our AI interviewer calls your phone and runs a realistic Keras interview — then scores it.
📞 Practice Keras — free 15 min
📕 Buy this interview preparation book: 100 Keras questions & answers — PDF + EPUB for $5

All 100 Keras questions · All topics