Path: blob/master/cpd5.2/notebooks/python_sdk/deployments/foundation_models/Use Time Series Foundation Models and timeseries data to predict energy demand.ipynb
6412 views
Use Time Series Foundation Models and time series data to predict energy demand
Disclaimers
Use only Projects and Spaces that are available in watsonx context.
Notebook content
This notebook demonstrates the use of a pre-trained time series foundation model for multivariate forecasting tasks and showcases the variety of features available in Time Series Foundation Models.
Some familiarity with Python is helpful. This notebook uses Python 3.12.
Learning goals
The learning goals of this notebook are:
To explore Time Series Foundation Models
To initialize the model
To forecast based on historical data
Contents
This notebook contains the following parts:
Install dependencies
Note: ibm-watsonx-ai
documentation can be found here.
Successfully installed wget-3.2
Successfully installed contourpy-1.3.2 cycler-0.12.1 fonttools-4.58.0 kiwisolver-1.4.8 matplotlib-3.10.3 numpy-2.2.6 pillow-11.2.1 pyparsing-3.2.3
Successfully installed anyio-4.9.0 certifi-2025.4.26 charset-normalizer-3.4.2 h11-0.16.0 httpcore-1.0.9 httpx-0.28.1 ibm-cos-sdk-2.14.1 ibm-cos-sdk-core-2.14.1 ibm-cos-sdk-s3transfer-2.14.1 ibm-watsonx-ai-1.3.20 idna-3.10 jmespath-1.0.1 lomond-0.3.3 pandas-2.2.3 pytz-2025.2 requests-2.32.2 sniffio-1.3.1 tabulate-0.9.0 typing_extensions-4.13.2 tzdata-2025.2 urllib3-2.4.0
Define credentials
Authenticate the watsonx.ai Runtime service on IBM Cloud Pak for Data. You need to provide the admin's username
and the platform url
.
Use the admin's api_key
to authenticate watsonx.ai Runtime services:
Alternatively you can use the admin's password
:
Working with projects
First of all, you need to create a project that will be used for your work. If you do not have a project created already, follow the steps below:
Open IBM Cloud Pak main page
Click all projects
Create an empty project
Copy
project_id
from url and paste it below
Action: Assign project ID below
Create APIClient
instance
Training dataset
This tutorial uses the Hourly energy demand dataset dataset, which contains four years of electrical consumption and generation data for Spain. It is a modified version of the Hourly energy demand generation and weather. For simplicity, the dataset has been prepared to have no missing values and no irrelevant columns.
Show the last few rows of the dataset.
Describe the data.
Split the data
The purpose of this notebook is to demonstrate the core functionality of features available in Time Series Foundation Models. The selected model, ibm/granite-ttm-512-96-r2
, requires a minimum context length of 512. Therefore, the dataset will be split into a historical dataset containing 512 rows, while the next 96 lines will be used to check the consistency of the predictions.
Visualize the data
Time Series Foundation Models in watsonx.ai
List available models
Defining model
You need to specify model_id
that will be used for inferencing:
TSModelInference
is a wrapper for time series models available from watsonx.ai, designed to forecast future values based on historical data.
Defining the model parameters
We need to provide a set of model parameters that will influence the result:
Plot predictions along with the historical data.
Summary and next steps
You successfully completed this notebook!
You learned how to use Time Series Foundation Models in real life applications.
Check out our Online Documentation for more samples, tutorials, documentation, how-tos, and blog posts.
Authors
Aleksandra Kłeczek, Software Engineer at watsonx.ai.
Rafał Chrzanowski, Software Engineer Intern at watsonx.ai.
Copyright © 2025 IBM. This notebook and its source code are released under the terms of the MIT License.