Path: blob/master/cloud/notebooks/python_sdk/deployments/foundation_models/Use Time Series BYOM and time series data to predict energy demand.ipynb
6408 views
Use Time Series BYOM 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 process of deploying model for Time Series as well as its use 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.11.
Learning goals
The learning goals of this notebook are:
Store TS model previously available in your COS
Deploy TS model
To explore Time Series BYOM
To forecast based on historical data
Contents
This notebook contains the following parts:
1. Set up the environment
Before you use the sample code in this notebook, you must perform the following setup tasks:
Create a watsonx.ai Runtime Service instance (a free plan is offered and information about how to create the instance can be found here).
Install and import the ibm-watsonx-ai
and dependecies
Note: ibm-watsonx-ai
documentation can be found here.
Defining the watsonx.ai credentials
This cell defines the watsonx.ai credentials required to work with watsonx Foundation Model inferencing.
Action: Provide the IBM Cloud user API key. For details, see documentation.
Defining the project id
The deploymeny of Time Series FM requires project id that provides the context for the call. We will obtain the id from the project in which this notebook runs. Otherwise, please provide the project id.
CONNECTION_ID - connection asset ID to your data source which will store custom foundation model files.
BUCKET_NAME - bucket which will store your custom foundation models files.
FILE_PATH - path to your custom foundation models files. In most cases empty string - "".
Create custom model repository
Perform custom model deployment
3. Prepare 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, requires a minimum context length of 1024. Therefore, the dataset will be split into a historical dataset containing 1024 rows, while the next 96 lines will be used to check the consistency of the predictions.
Visualize the data
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.
6. Summary and next steps
You successfully completed this notebook!
You learned how to use Time Series BYOM in real life applications.
Check out our Online Documentation for more samples, tutorials, documentation, how-tos, and blog posts.
Authors
Filip Żmijewski, Software Engineer at watsonx.ai.
Copyright © 2025 IBM. This notebook and its source code are released under the terms of the MIT License.