How use Tutorial on Time Series Forecasting (for beginners)

I am following Tensorflow’s tutorial on time series forecasting https://www.tensorflow.org/tutorials/structured_data/time_series#dense. I created and saved the model like in this tutorial. There are many examples in the manual for learning, but few use of it.

My question is how to use the saved model in another script? How to predict temperature e.g. “01.01.2017 00:10:00”? How to get temperature value in normal format?
Example code from tutorial: Google Colab

Hi @alex_kosh ,

  1. Load the Saved Model: First, you need to load the model you’ve saved during training.
  2. Prepare the Input Data: Ensure that the input data for prediction is in the same format as the data used for training the model.
  3. Make Predictions: Use the model to make predictions on the new data.
  4. Interpret the Results: Convert the predicted output into a human-readable format (like temperature values).
import tensorflow as tf
import numpy as np
import pandas as pd


model = tf.keras.models.load_model('path_to_my_model.h5')


timestamp = pd.to_datetime("01.01.2017 00:10:00")
input_data = data[data['timestamp'] < timestamp].tail(5)


input_data = np.array(input_data).reshape(1, -1)  # Assuming your model expects this shape


predicted_temperature = model.predict(input_data)

print(f"Predicted Temperature: {predicted_temperature[0]}")

Ensuring input data for prediction is preprocessed and formatted exactly as it was when you trained the model. This might involve normalizing or scaling the data, reshaping it, or extracting relevant features in the same way you did during training.

Also, if your model predicts a scaled or normalized value, you’ll need to reverse that scaling or normalization to interpret the output as an actual temperature value.

I hope this helps.

Thanks.