This project demonstrates time series forecasting using the tsfm_public library and the TinyTimeMixer model. It loads energy consumption data, performs preprocessing, generates forecasts, and visualizes the results.
It is one of the many pretrained models from the family of "Granite Time Series". This models are developed by IBM. This models performs on principles of zero/few-shot learning, hence, it is used to provide predictions even with limited training data. This model is lightweight meaning it could run with minimial hardware requirements. This model is useful in scenarios where series data is scarce or diverse.
Before running the code, ensure you have the following installed:
- Python 3.x
venv(virtual environment module)pip(Python package installer)
-
Create a virtual environment:
python -m venv venv
-
Activate the virtual environment:
-
On Windows:
.\venv\Scripts\activate
-
On macOS and Linux:
source venv/bin/activate
-
-
Install the necessary dependencies:
pip install "tsfm_public[notebooks] @ git+[https://github.com/ibm-granite/granite-tsfm.git@v0.2.12](https://github.com/ibm-granite/granite-tsfm.git@v0.2.12)"pip install -r requirements.txt
Execute the demo.py script:
```bash
python demo.py
```
This script will:
- Load the energy consumption dataset (
energy_dataset.csv). - Fill missing data using forward fill.
- Display the last few rows of the preprocessed data.
- Generate a plot of the target time series.
- Load the TinyTimeMixer forecasting model (
ibm-granite/granite-timeseries-ttm-r1). - Create a forecasting pipeline.
- Generate forecasts for the target time series.
- Display the last few rows of the forecast.
- Generate and display a plot comparing the actual data with the forecast.
The data loaded is used to build a chart.

The dataset used in this demo is energy_dataset.csv, which contains hourly energy consumption data. It should be placed in the archive directory within the project root.
matplotlibpandastsfm_public(fromgit+https://github.com/ibm-granite/granite-tsfm.git@v0.2.12)torch>=1.8.0numpy>=1.19.0h5py>=3.1.0matplotlib>=3.3.0scikit-learn>=0.24.0tqdm>=4.50.0pandas>=1.1.0seaborn>=0.11.0scipy>=1.6.0tensorboard>=2.5.0
- You can experiment with different TinyTimeMixer models by changing the model name in the
from_pretrainedfunction. - The
context_lengthparameter controls the number of historical data points used for forecasting. - Feel free to modify the script to explore different forecasting scenarios and datasets.