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. Use this approach when you have a single historical series and need point forecasts.
Prerequisites
- Chronax and JAX must be installed.
- The historical data
ymust be a 1-Djnp.ndarrayof typefloat32.
Steps
1. Prepare the historical data
Start by importing JAX and creating a sample 1-D array representing your historical time series data. Chronax models expect data to be in float32 format.
import jax.numpy as jnp
from chronax.models import AutoARIMA
# Create a sample historical series (e.g., 100 time steps)
y = jnp.arange(100, dtype=jnp.float32) + jnp.sin(jnp.linspace(0, 10, 100))
2. Initialize the AutoARIMA model
Import the model from chronax.models and initialize it. AutoARIMA requires no arguments for basic usage, relying on internal heuristics to find the best parameters.
# Initialize the model
model = AutoARIMA()
3. Fit the model to the data
Use the fit method, passing only the historical series y. The model will internally search for the optimal ARIMA order (p, d, q) and seasonal components (P, D, Q, m).
# Fit the model
params, state = model.fit(y)
4. Generate the forecast
Use the predict method, passing the fitted params and state, along with the forecast horizon h (the number of future steps to predict). The result is a dictionary containing the forecast mean.
# Define the forecast horizon (e.g., 10 steps ahead)
h = 10
# Generate the forecast
forecast_output = model.predict(params, state, h)
# Access the mean forecast array
mean_forecast = forecast_output["mean"]
print(f"Forecast shape: {mean_forecast.shape}")
print(f"First 5 forecast values: {mean_forecast[:5]}")
Full example
This complete example demonstrates the entire workflow from data generation to generating the final forecast.
import jax.numpy as jnp
from chronax.models import AutoARIMA
# 1. Prepare the historical data
# Create a sample historical series (100 time steps)
y = jnp.arange(100, dtype=jnp.float32) + jnp.sin(jnp.linspace(0, 10, 100))
# 2. Initialize the AutoARIMA model
model = AutoARIMA()
# 3. Fit the model to the data
params, state = model.fit(y)
# 4. Generate the forecast
h = 10
forecast_output = model.predict(params, state, h)
# Access the mean forecast
mean_forecast = forecast_output["mean"]
print(f"Historical data length: {len(y)}")
print(f"Forecast length (h): {h}")
print(f"Mean forecast array: {mean_forecast}")
Next steps
- To include uncertainty, see the guide on "Adding prediction intervals using
level". - To use a different model, explore
chronax.models.TFT(Temporal Fusion Transformer). - For a combined fit and predict step, use the convenience method
model.forecast.