9951 explained code solutions for 126 technologies


python-tensorflowHow do I use a Python TensorFlow Keras model to make predictions?


Using a Python TensorFlow Keras model to make predictions involves the following steps:

  1. Load the model:
from keras.models import load_model
model = load_model('model.h5')
  1. Prepare the input data:
import numpy as np
x_test = np.array([[1,2,3]])
  1. Make predictions:
prediction = model.predict(x_test)
print(prediction)
# [[0.1, 0.2, 0.7]]

The model will output an array of probabilities, representing the likelihood of each possible outcome.

For more information, please refer to the Keras documentation and the TensorFlow documentation.

Edit this code on GitHub