Forecast a univariate series using AutoARIMA
Use this guide to initialize, fit, and predict future values for a single time series using the automated ARIMA model implementation in Chronax. This is the standard starting point for time series forecasting.
Prerequisites
- You have installed Chronax and its dependencies (JAX).
- The target series
ymust be a 1-Djnp.ndarrayof typefloat32.
import jax.numpy as jnp
from chronax.models import AutoARIMA
Steps
1. Prepare the input data
Chronax models operate on JAX arrays. Define your historical time series data, ensuring it is a 1-D array of float32.
# Historical data (e.g., 100 observations)
y = jnp.array([
10.1, 10.5, 10.3, 10.9, 11.2, 11.5, 11.0, 11.8, 12.0, 12.5
] * 10, dtype=jnp.float32)
2. Initialize the AutoARIMA model
Instantiate the AutoARIMA model. This model automatically searches for the optimal ARIMA order (p, d, q) based on the input data during the fitting process.
model = AutoARIMA()
3. Fit the model to the historical data
Call the fit method, passing the historical series y. The model learns its internal parameters and determines the best structure based on this data.
params = model.fit(y)
4. Predict future steps
Use the predict method to generate forecasts for a specified horizon h. The result is a dictionary containing the forecast mean and potentially other metrics.
# Define the forecast horizon (e.g., 12 steps ahead)
h = 12
# Generate the forecast
out = model.predict(h)
# Access the mean forecast array
mean_forecast = out["mean"]
print(f"Forecast shape: {mean_forecast.shape}")
Full example
This complete example demonstrates the end-to-end workflow for univariate forecasting.
import jax.numpy as jnp
from chronax.models import AutoARIMA
# 1. Prepare data (100 observations)
y = jnp.array([
10.1, 10.5, 10.3, 10.9, 11.2, 11.5, 11.0, 11.8, 12.0, 12.5
] * 10, dtype=jnp.float32)
# 2. Initialize the model
model = AutoARIMA()
# 3. Fit the model
params = model.fit(y)
# 4. Predict future steps (h=12)
h = 12
out = model.predict(h)
# Print results
print("Historical data length:", len(y))
print("Forecast length:", len(out["mean"]))
print("First 5 forecast values:", out["mean"][:5])
Next steps
- Learn how to include prediction intervals using the
levelargument inmodel.predict. - Explore advanced models like
chronax.models.NBEATSfor deep learning forecasts. - Use
model.forecastfor a combined fit and predict operation. - Understand the structure of the returned
paramsdictionary.