Forecast a Univariate Series
This guide shows you how to initialize a Chronax model, fit it to a single time series, and generate future predictions. Use this approach when you have a single target variable without external influences.
Prerequisites
- Chronax installed (
pip install chronax). - The input time series
ymust be a 1-Djnp.ndarrayof typefloat32.
import jax.numpy as jnp
from chronax.models import AutoARIMA # Assuming AutoARIMA is available
Steps
1. Prepare the input data
Define your historical time series data y. Chronax models expect JAX arrays (jnp.ndarray).
# Example: 20 historical observations
y = jnp.array([
10.1, 10.5, 11.2, 10.9, 11.5, 12.0, 12.5, 13.0, 13.5, 14.0,
14.5, 15.0, 15.5, 16.0, 16.5, 17.0, 17.5, 18.0, 18.5, 19.0
], dtype=jnp.float32)
2. Initialize the model
Instantiate the desired forecasting model. We use AutoARIMA as an example, which automatically selects the best ARIMA parameters.
# NOTE: The specific constructor arguments are missing from the provided specification.
# We assume a default initialization is possible.
model = AutoARIMA() # TODO: confirm AutoARIMA constructor arguments against the API
3. Fit the model to the data
Call the fit method, passing the historical time series y. The model learns the underlying patterns, trend, and seasonality from this data.
params = model.fit(y)
4. Generate the forecast
Use the predict method on the fitted parameters to generate future values. You must specify the forecast horizon h. Here, we forecast 5 steps ahead.
h = 5
forecast_out = model.predict(params, h=h)
# Access the mean forecast values
mean_forecast = forecast_out["mean"]
print(f"Forecasted values for the next {h} steps:")
print(mean_forecast)
Full example
This block combines all steps to initialize, fit, and forecast a univariate series.
import jax.numpy as jnp
from chronax.models import AutoARIMA
# 1. Prepare data
y = jnp.array([
10.1, 10.5, 11.2, 10.9, 11.5, 12.0, 12.5, 13.0, 13.5, 14.0,
14.5, 15.0, 15.5, 16.0, 16.5, 17.0, 17.5, 18.0, 18.5, 19.0
], dtype=jnp.float32)
# 2. Initialize model
model = AutoARIMA() # TODO: confirm AutoARIMA constructor arguments against the API
# 3. Fit the model
params = model.fit(y)
# 4. Generate the forecast (5 steps ahead)
h = 5
forecast_out = model.predict(params, h=h)
# Extract the results
mean_forecast = forecast_out["mean"]
print(f"Historical data length: {len(y)}")
print(f"Forecast horizon (h): {h}")
print(f"Mean forecast: {mean_forecast}")
Next steps
- See the guide on "Adding prediction intervals" using the
levelargument inmodel.predict. - Explore other models like
HoltWintersfor series with clear trend and seasonality. - Learn how to use the convenience function
model.forecastfor combined fit and predict operations.