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 optimal ARIMA parameters for your data.
Prerequisites
- Chronax installed (
pip install chronax). - Imports:
jax.numpyand the model. - Data assumption:
yis a 1-Djnp.ndarrayof typefloat32.
Steps
1. Prepare the time series data
Start by importing JAX and creating your univariate time series (y). Chronax models require data to be JAX arrays (jnp.ndarray) and typically prefer float32 precision.
import jax.numpy as jnp
# Create a sample time series (e.g., 10 observations)
y = jnp.array([10.0, 12.0, 15.0, 14.0, 16.0, 18.0, 20.0, 21.0, 23.0, 25.0], dtype=jnp.float32)
2. Initialize the AutoARIMA model
Import AutoARIMA from chronax.models and instantiate it. Since AutoARIMA is an automatic model, it requires no hyperparameters during initialization.
from chronax.models import AutoARIMA
model = AutoARIMA()
3. Fit the model to the data
Call the fit method, passing your time series y. The model will internally search for the optimal autoregressive (p), integrated (d), and moving average (q) orders.
model = model.fit(y)
4. Generate the forecast
Use the predict method on the fitted model, specifying the forecast horizon h (the number of future steps you want to predict). The result is a dictionary containing the forecast mean and, optionally, prediction intervals.
h = 5 # Forecast 5 steps ahead
forecast_output = model.predict(h)
# Access the mean forecast array
mean_forecast = forecast_output["mean"]
print(f"Forecast mean for {h} steps:\n{mean_forecast}")
Full example
This complete example combines the steps to generate and print the resulting forecast array.
import jax.numpy as jnp
from chronax.models import AutoARIMA
# 1. Prepare the time series data
y = jnp.array([10.0, 12.0, 15.0, 14.0, 16.0, 18.0, 20.0, 21.0, 23.0, 25.0], dtype=jnp.float32)
h = 5
# 2. Initialize the AutoARIMA model
model = AutoARIMA()
# 3. Fit the model to the data
model = model.fit(y)
# 4. Generate the forecast
forecast_output = model.predict(h)
mean_forecast = forecast_output["mean"]
print(f"Input series length: {len(y)}")
print(f"Forecast horizon (h): {h}")
print(f"Mean forecast:\n{mean_forecast}")
Next steps
- Learn how to include prediction intervals by setting the
levelargument inmodel.predict(h, level=95). - Explore how to use exogenous features by passing the
Xarray tomodel.fit(y, X=X_train)andmodel.predict(h, X=X_future). - Use the convenience function
model.forecast(y, h)for a single-call fit and predict operation. - Try other automatic models like
AutoETSorAutoTBATS.