Improve Forecast Accuracy with TimeGPT

This guide demonstrates how to improve forecast accuracy using TimeGPT. We use hourly electricity price data from Germany as an illustrative example. Before you begin, make sure you have initialized the NixtlaClient object with your API key.

Tip: You can run these steps interactively in a Colab notebook:

Forecasting Results Overview

Below is a summary of our experiments and the corresponding accuracy improvements. We progressively refine forecasts by adding fine-tuning steps, adjusting loss functions, increasing the number of fine-tuned parameters, incorporating exogenous variables, and switching to a long-horizon model.


Step-by-Step Guide

1

1. Install and Import Packages

Make sure all necessary libraries are installed and imported. Then set up the Nixtla client (replace with your actual API key).

Nixtla Client Setup
import numpy as np
import pandas as pd
from utilsforecast.evaluation import evaluate
from utilsforecast.plotting import plot_series
from utilsforecast.losses import mae, rmse
from nixtla import NixtlaClient

nixtla_client = NixtlaClient(
    # api_key='my_api_key_provided_by_nixtla'
)
2

2. Load the Dataset

We use hourly electricity price data from Germany (unique_id == "DE"). The final two days (48 data points) form the test set.

Load Dataset
df = pd.read_csv('https://raw.githubusercontent.com/Nixtla/transfer-learning-time-series/main/datasets/electricity-short-with-ex-vars.csv')
df['ds'] = pd.to_datetime(df['ds'])

df_sub = df.query('unique_id == "DE"')

df_train = df_sub.query('ds < "2017-12-29"')
df_test = df_sub.query('ds >= "2017-12-29"')

df_train.shape, df_test.shape

Hourly electricity price for Germany (training period highlighted).

3

3. Benchmark Forecast with TimeGPT

Info: We first generate a zero-shot forecast using TimeGPT, which captures overall trends but may struggle with short-term fluctuations.

Zero-shot Forecasting
fcst_timegpt = nixtla_client.forecast(
    df=df_train[['unique_id', 'ds', 'y']],
    h=2*24,
    target_col='y',
    level=[90, 95]
)

Evaluation Metrics

unique_idmetricTimeGPT
DEmae18.519
DErmse20.038

Zero-shot TimeGPT Forecast

4

4. Methods to Enhance Forecasting Accuracy

Use these strategies to refine and improve your forecast:

5

5. Conclusion and Next Steps

Key takeaways:

  • Increase the number of fine-tuning steps.
  • Experiment with different loss functions.
  • Incorporate exogenous data.
  • Consider a specialized long-horizon forecasting model.

These strategies offer consistent improvements in forecast accuracy. We recommend systematically experimenting with each approach to find the best combination for your data.

Success: Small refinements—like adding exogenous data or adjusting fine-tuning parameters—can significantly improve your forecasting results.


Result Summary (Repeated for Convenience)