Esc
Ask AIAnswers may be inaccurate; check the linked pages.Esc
Ask anything about these docs, like how to get started or what a function does.

Forecast a univariate series using AutoARIMA

This guide shows you how to initialize, fit, and forecast a single time series using Chronax's automatic ARIMA implementation, AutoARIMA. Use this approach when you need robust, interpretable forecasts without manual hyperparameter tuning.

Prerequisites

  • Chronax and JAX installed.
  • y (the historical time series) must be a 1-D jnp.ndarray of type float32.
  • Imports: jax.numpy as jnp and chronax.models.AutoARIMA.

Steps

1. Prepare the historical data

First, create or load your historical time series data (y). Chronax models operate on JAX arrays (jnp.ndarray), so ensure your data is converted and cast to float32.

import jax.numpy as jnp
import numpy as np # Used here only for synthetic data generation

# Create a synthetic time series (e.g., 100 points)
np.random.seed(42)
y_np = 10 + np.arange(100) * 0.5 + np.sin(np.arange(100) * 0.5) + np.random.normal(0, 1, 100)

# Convert to the required JAX array format
y = jnp.asarray(y_np, dtype=jnp.float32)

print(f"Data shape: {y.shape}")
print(f"Data dtype: {y.dtype}")

2. Initialize the AutoARIMA model

Import the AutoARIMA model from chronax.models. Since AutoARIMA automatically searches for the best parameters (p, d, q), initialization requires no arguments.

from chronax.models import AutoARIMA

# Initialize the model
model = AutoARIMA()

3. Fit the model to the data

Call the .fit() method, passing your historical time series y. The model will internally search for the optimal ARIMA order based on information criteria (like AIC or BIC).

# Fit the model
fit_result = model.fit(y)

print("Model fitting complete.")
# The fit_result dictionary contains diagnostic information, 
# such as the selected order and optimization status.
# print(fit_result) 

4. Generate the forecast

Use the .predict() method to generate forecasts for a specified horizon h. The result is a dictionary containing the forecast mean and, by default, no prediction intervals.

# Define the forecast horizon (e.g., 10 steps ahead)
h = 10

# Generate the forecast
forecast_output = model.predict(h=h)

# The output is a dictionary. Access the mean forecast array:
mean_forecast = forecast_output["mean"]

print(f"Forecast shape: {mean_forecast.shape}")
print(f"Mean forecast for the next {h} steps:\n{mean_forecast}")

Full example

This complete script initializes the data, fits the model, and prints the resulting forecast mean.

import jax.numpy as jnp
import numpy as np
from chronax.models import AutoARIMA

# --- 1. Prepare the historical data ---
np.random.seed(42)
y_np = 10 + np.arange(100) * 0.5 + np.sin(np.arange(100) * 0.5) + np.random.normal(0, 1, 100)
y = jnp.asarray(y_np, dtype=jnp.float32)

# --- 2. Initialize the AutoARIMA model ---
model = AutoARIMA()

# --- 3. Fit the model to the data ---
print("Starting fit...")
model.fit(y)
print("Fit complete.")

# --- 4. Generate the forecast ---
h = 10
forecast_output = model.predict(h=h)

mean_forecast = forecast_output["mean"]

print(f"\nForecast Horizon (h): {h}")
print(f"Mean forecast:\n{mean_forecast}")

Next steps

  • To include prediction intervals, see the guide on "Adding prediction intervals" and use the level argument in model.predict().
  • To incorporate external features, see the guide on "Using exogenous features" and the X argument in model.fit().
  • Explore other models like chronax.models.NBEATS for deep learning approaches.
  • Review the fit_result dictionary for the selected ARIMA order parameters (p, d, q).