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 the built-in AutoARIMA model, which automatically selects the best ARIMA parameters for your data. Use this approach when you need a robust statistical baseline forecast without manual parameter tuning.

Prerequisites

  • Chronax installed.
  • y (the historical time series) must be a 1-D jnp.ndarray of type float32.
  • h (the forecast horizon) must be an integer.

Steps

1. Prepare the historical data

Start by importing JAX and creating a sample historical time series (y). Chronax models expect inputs to be JAX arrays (jnp.ndarray) and typically use float32 precision.

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

# Create a sample time series (e.g., 100 historical points)
# Use a simple seasonal pattern for demonstration
T = 100
y_np = 50 + np.arange(T) * 0.5 + np.sin(np.arange(T) / 5) * 10 + np.random.randn(T) * 2
y = jnp.asarray(y_np, dtype=jnp.float32)

print(f"Historical series shape: {y.shape}")

2. Initialize the AutoARIMA model

Import the model from chronax.models. Since AutoARIMA automatically searches for optimal parameters (p, d, q, P, D, Q, m), you typically initialize it without any arguments.

# 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 determine the best-fitting ARIMA structure based on information criteria.

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

print("Model fitting complete.")
# Note: The 'params' object holds the optimized model parameters.

4. Generate the forecast

Use the predict method, specifying the forecast horizon h. The method returns a dictionary containing the forecast results, including the mean prediction.

# Define the forecast horizon
h = 14

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

# Access the mean forecast array
mean_forecast = forecast_output["mean"]

print(f"Forecast horizon (h): {h}")
print(f"Mean forecast shape: {mean_forecast.shape}")

Full example

This complete example demonstrates the entire workflow from data preparation to generating the final forecast.

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

# 1. Prepare the historical data
T = 100
y_np = 50 + np.arange(T) * 0.5 + np.sin(np.arange(T) / 5) * 10 + np.random.randn(T) * 2
y = jnp.asarray(y_np, dtype=jnp.float32)

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

# 3. Fit the model to the data
params = model.fit(y)

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

# Extract the results
mean_forecast = forecast_output["mean"]

print(f"Historical data points: {y.shape[0]}")
print(f"Forecasted points: {mean_forecast.shape[0]}")
print("\nFirst 5 forecast values:")
print(mean_forecast[:5])

Next steps

  • To quantify uncertainty, see the guide on adding prediction intervals using the level argument in model.predict.
  • To include external factors, learn how to use the X argument in model.fit and model.predict.
  • Explore other statistical baselines like AutoETS or SeasonalNaive.
  • For large-scale forecasting, investigate the model.forecast utility function.