Forecast a univariate series using AutoARIMA
This guide shows you how to initialize, fit, and forecast a single time series using the AutoARIMA model, which automatically selects the best ARIMA parameters for your data.
Prerequisites
- Chronax installed (
pip install chronax). - Data must be a 1-D array of observations (
y). yis ajnp.ndarrayof typefloat32.
Steps
1. Prepare the data and import the model
Start by importing the necessary libraries and creating a sample univariate time series (y).
import jax.numpy as jnp
from chronax.models import AutoARIMA
# Create a sample time series (e.g., 100 observations)
y = jnp.arange(100, dtype=jnp.float32) + jnp.sin(jnp.linspace(0, 10, 100))
# Define the forecast horizon
H = 10
2. Initialize the AutoARIMA model
Initialize the AutoARIMA model. Since this model automatically handles parameter selection, typically no arguments are required during initialization, but you may specify constraints if needed.
# TODO: confirm AutoARIMA constructor arguments against the API
model = AutoARIMA()
3. Fit the model to the historical data
Fit the model using the historical observations (y). The fit method trains the model parameters based on the input data.
# The standard Chronax fit contract is model.fit(y, X=None)
params = model.fit(y)
4. Generate the forecast
Use the predict method on the fitted model to generate forecasts for the desired horizon (H). The output is a dictionary containing the forecast mean and potentially other metrics.
# The standard Chronax predict contract is model.predict(h, level=None)
forecast_output = model.predict(H)
# Access the mean forecast
mean_forecast = forecast_output["mean"]
print(f"Forecast shape: {mean_forecast.shape}")
Full example
This complete example combines the steps to initialize, fit, and forecast a series using AutoARIMA.
import jax.numpy as jnp
from chronax.models import AutoARIMA
# 1. Prepare data
y = jnp.arange(100, dtype=jnp.float32) + jnp.sin(jnp.linspace(0, 10, 100))
H = 10
# 2. Initialize model
# TODO: confirm AutoARIMA constructor arguments against the API
model = AutoARIMA()
# 3. Fit the model
params = model.fit(y)
# 4. Generate the forecast
forecast_output = model.predict(H)
# Access the mean forecast
mean_forecast = forecast_output["mean"]
print(f"Historical data length: {len(y)}")
print(f"Forecast horizon (H): {H}")
print(f"Mean forecast (first 5 points): {mean_forecast[:5]}")
Next steps
- See the guide on "Adding prediction intervals" using the
levelargument inmodel.predict. - Explore other classical models like
SeasonalNaiveorTheta. - Learn how to use
BatchedForecasterto handle multiple time series efficiently. - Investigate foundation models like
chronosortimesfmfor complex forecasting tasks.