TimeGEN-1 Quickstart (Azure)

TimeGEN-1 is TimeGPT optimized for the Azure infrastructure. It is a production ready, generative pretrained transformer for time series. It’s capable of accurately predicting various domains such as retail, electricity, finance, and IoT with just a few lines of code 🚀.

Step 1: Set up a TimeGEN-1 endpoint account and generate your API key on Azure

  • Go to ml.azure.com
  • Sign in or create an account at Microsoft
  • Click on ‘Models’ in the sidebar
  • Search for ‘TimeGEN’ in the model catalog
  • Select TimeGEN-1
Azure Model Catalog landing page. Search for forecast and TimeGEN-1 comes up as the only option.
  • Click ‘Deploy’ and this will create an Endpoint
TimeGEN-1 in the model catalog. Cursor is on the Deploy button indicating what to select to deploy TimeGEN-1.
  • Go to ‘Endpoint’ in the sidebar and you will see your TimeGEN-1 endpoint there
  • In that Endpoint are the base URL and API Key you will use
Endpoint is highlighted in the side panel. The main panel shows the endpoint and API key for the TimeGEN-1 endpoint, with buttons where you can copy the information.

Step 2: Install Nixtla

In your favorite Python development environment:

Install nixtla with pip:

pip install nixtla

Step 3: Import the Nixtla TimeGPT client

from nixtla import NixtlaClient

You can instantiate the NixtlaClient class providing your authentication API key.

nixtla_client = NixtlaClient(
    base_url = "YOUR_BASE_URL",
    api_key = "YOUR_API_KEY"
)

Step 4: Start making forecasts!

Now you can start making forecasts! Let’s import an example using the classic AirPassengers dataset. This dataset contains the monthly number of airline passengers in Australia between 1949 and 1960. First, load the dataset and plot it:

import pandas as pd
df = pd.read_csv('https://raw.githubusercontent.com/Nixtla/transfer-learning-time-series/main/datasets/air_passengers.csv')
df.head()
timestampvalue
01949-01-01112
11949-02-01118
21949-03-01132
31949-04-01129
41949-05-01121
nixtla_client.plot(df, time_col='timestamp', target_col='value')

📘

Data Requirements

  • Make sure the target variable column does not have missing or non-numeric values.
  • Do not include gaps/jumps in the datestamps (for the given frequency) between the first and late datestamps. The forecast function will not impute missing dates.
  • The format of the datestamp column should be readable by Pandas (see this link for more details).

For further details go to Data Requirements.

👍

Save figures made with TimeGEN

The plot method automatically displays figures when in a notebook environment. To save figures locally, you can do:

fig = nixtla_client.plot(df, time_col='timestamp', target_col='value')

fig.savefig('plot.png', bbox_inches='tight')

Make forecasts

Next, forecast the next 12 months using the SDK forecast method. Set the following parameters:

  • df: A pandas DataFrame containing the time series data.
  • h: Horizons is the number of steps ahead to forecast.
  • freq: The frequency of the time series in Pandas format. See pandas’ available frequencies. (If you don’t provide any frequency, the SDK will try to infer it)
  • time_col: The column that identifies the datestamp.
  • target_col: The variable to forecast.
timegen_fcst_df = nixtla_client.forecast(df=df, h=12, freq='MS', time_col='timestamp', target_col='value')
timegen_fcst_df.head()
INFO:nixtla.nixtla_client:Validating inputs...
INFO:nixtla.nixtla_client:Preprocessing dataframes...
INFO:nixtla.nixtla_client:Restricting input...
INFO:nixtla.nixtla_client:Calling Forecast Endpoint...
timestampTimeGPT
01961-01-01437.837921
11961-02-01426.062714
21961-03-01463.116547
31961-04-01478.244507
41961-05-01505.646484
nixtla_client.plot(df, timegen_fcst_df, time_col='timestamp', target_col='value')