Nixtla's TimeGPT: Making Time Series Predictions Accessible to Everyone (Predict the Future with Ease: Nixtla's TimeGPT Explained)
Nixtla's TimeGPT: Making Time Series Predictions Accessible to Everyone (Predict the Future with Ease: Nixtla's TimeGPT Explained)
Introduction
Nixtla’s TimeGPT is a generative pre-trained forecasting model for time series data. TimeGPT can produce accurate forecasts for new time series without training, using only historical values as inputs.
I would like to forecast the U.S CPI for next 2 and 6 months using timeGPT in the colab environment.
Download U.S CPI database from here.
Please put it to the colab’s file directory.
Install Nixtlats and import timeGPT
!pip install nixtlats
from nixtlats import TimeGPT
Introduce Your API
You can instantiate the TimeGPT
class providing your credentials(API Keys).
timegpt = TimeGPT(
  # defaults to os.environ.get("TIMEGPT_TOKEN")
  token = '
API Key will be here'
)
Validate of your token calling the validate_token
method:
timegpt.validate_token()
U.S CPI Forecast
Now you can begin making forecasts! Let's import an example using the classic U.S. CPI dataset. This dataset contains the monthly CPI in the U.S. between 1948:1 and 2024:1. First, let's load the dataset and plot it.
import pandas as pd
file_path = 'U.S-2024-01-cpi.csv'
df = pd.read_csv(file_path)
df.head()
timegpt.plot(df, time_col='date', target_col='value')
Next, forecast the next 2 months using the SDK forecast
method. Set the following parameters:
df
: A pandas dataframe containing the time series data.h
: The number of steps ahead to forecast.freq
: The frequency of the time series in Pandas format.time_col
: Column that identifies the datestamp column.target_col
: The variable that we want to forecast.
timegpt_fcst_df = timegpt.forecast(df=df, h=2, freq='MS', time_col='date', target_col='value')
timegpt_fcst_df.head()
timegpt.plot(df, timegpt_fcst_df, time_col='date', target_col='value')
You can also produce a longer forecasts increasing the horizon parameter. For example, let's forecast the next 6 months.
timegpt_fcst_df = timegpt.forecast(df=df, h=6, time_col='date', target_col='value', freq='MS')
timegpt.plot(df, timegpt_fcst_df, time_col='date', target_col='value')
Code is here
Engin YILMAZ(
)