Forecast a univariate series using AutoARIMA
This guide shows you how to initialize, fit, and generate future predictions for a single time series using the automatic model selection capabilities of AutoARIMA. Use this approach when you need a robust forecast without manually configuring model orders.
Prerequisites
- Chronax installed (
pip install chronax). - Imports:
jax.numpyand the chosen model. - Input data
ymust be a 1-Djnp.ndarrayof typefloat32.
Steps
1. Prepare the input data
Define your historical time series data (y). Chronax models expect JAX arrays, typically of type float32.
import jax.numpy as jnp
from chronax.models import AutoARIMA
# Create a dummy time series (e.g., 100 observations)
y = jnp.sin(jnp.linspace(0, 10 * jnp.pi, 100)) + jnp.linspace(0, 5, 100)
y = y.astype(jnp.float32)
2. Initialize the AutoARIMA model
Import the AutoARIMA class and instantiate it. Since this is an automatic model, no parameters are required for basic initialization.
model = AutoARIMA()
3. Fit the model to the historical data
Call the fit method, passing your historical data y. This step performs the model selection and parameter estimation.
# Fit the model
fitted_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 to predict). The result is a dictionary containing the forecast mean and other metrics.
# Define the forecast horizon (e.g., 10 steps)
H = 10
# Generate the forecast dictionary
forecast_output = fitted_model.predict(H)
# Extract the mean forecast array
mean_forecast = forecast_output["mean"]
print(f"Forecast shape: {mean_forecast.shape}")
Full example
This complete example demonstrates the entire workflow from data generation to extracting the final forecast array.
import jax.numpy as jnp
from chronax.models import AutoARIMA
# 1. Prepare the input data
# Create a dummy time series (100 observations, float32)
y = jnp.sin(jnp.linspace(0, 10 * jnp.pi, 100)) + jnp.linspace(0, 5, 100)
y = y.astype(jnp.float32)
# 2. Initialize the AutoARIMA model
model = AutoARIMA()
# 3. Fit the model to the historical data
fitted_model = model.fit(y)
# 4. Generate the forecast
H = 10
forecast_output = fitted_model.predict(H)
# Extract the mean forecast array
mean_forecast = forecast_output["mean"]
print(f"Historical data shape: {y.shape}")
print(f"Forecast horizon (H): {H}")
print(f"Mean forecast values (first 5): {mean_forecast[:5]}")
Next steps
- Learn how to add prediction intervals using the
levelparameter inpredict. - Explore other automatic models like
AutoETSorAutoTBATS. - Understand the
forecastmethod, which combines fitting and prediction into a single call. - Integrate exogenous features by passing an
Xarray tofit.