TimeGPT 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 π.
In your favorite Python development environment:
Install nixtla
with pip
:
You can instantiate the
NixtlaClient
class providing your authentication API key.
Check your API key status with the validate_api_key
method.
This will get you started, but for more secure usage, see Setting Up your API Key.
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:
timestamp | value | |
---|---|---|
0 | 1949-01-01 | 112 |
1 | 1949-02-01 | 118 |
2 | 1949-03-01 | 132 |
3 | 1949-04-01 | 129 |
4 | 1949-05-01 | 121 |
π 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 TimeGPT
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')
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.timestamp | TimeGPT | |
---|---|---|
0 | 1961-01-01 | 437.837921 |
1 | 1961-02-01 | 426.062714 |
2 | 1961-03-01 | 463.116547 |
3 | 1961-04-01 | 478.244507 |
4 | 1961-05-01 | 505.646484 |
You can also produce longer forecasts by increasing the horizon
parameter and selecting the timegpt-1-long-horizon
model. Use this
model if you want to predict more than one seasonal period of your data.
For example, letβs forecast the next 36 months:
timestamp | TimeGPT | |
---|---|---|
0 | 1961-01-01 | 436.843414 |
1 | 1961-02-01 | 419.351532 |
2 | 1961-03-01 | 458.943146 |
3 | 1961-04-01 | 477.876068 |
4 | 1961-05-01 | 505.656921 |
You can also produce a shorter forecast. For this, we recommend using
the default model, timegpt-1
.
TimeGPT 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 π.
In your favorite Python development environment:
Install nixtla
with pip
:
You can instantiate the
NixtlaClient
class providing your authentication API key.
Check your API key status with the validate_api_key
method.
This will get you started, but for more secure usage, see Setting Up your API Key.
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:
timestamp | value | |
---|---|---|
0 | 1949-01-01 | 112 |
1 | 1949-02-01 | 118 |
2 | 1949-03-01 | 132 |
3 | 1949-04-01 | 129 |
4 | 1949-05-01 | 121 |
π 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 TimeGPT
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')
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.timestamp | TimeGPT | |
---|---|---|
0 | 1961-01-01 | 437.837921 |
1 | 1961-02-01 | 426.062714 |
2 | 1961-03-01 | 463.116547 |
3 | 1961-04-01 | 478.244507 |
4 | 1961-05-01 | 505.646484 |
You can also produce longer forecasts by increasing the horizon
parameter and selecting the timegpt-1-long-horizon
model. Use this
model if you want to predict more than one seasonal period of your data.
For example, letβs forecast the next 36 months:
timestamp | TimeGPT | |
---|---|---|
0 | 1961-01-01 | 436.843414 |
1 | 1961-02-01 | 419.351532 |
2 | 1961-03-01 | 458.943146 |
3 | 1961-04-01 | 477.876068 |
4 | 1961-05-01 | 505.656921 |
You can also produce a shorter forecast. For this, we recommend using
the default model, timegpt-1
.