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 a Foundation Model

This guide shows you how to use the standard Chronax workflow to fit a time series and generate a forecast using a large pre-trained model, such as TimesFM. This approach is suitable when you want high-quality forecasts without extensive hyperparameter tuning.

Prerequisites

  • You have Chronax installed.
  • You need jax and jax.numpy for array handling.
  • The target series y must be a 1-D jnp.ndarray of type float32.

Steps

1. Prepare the input data

Chronax models require input data to be JAX NumPy arrays (jnp.ndarray). Define your historical time series data y.

import jax.numpy as jnp
from chronax.models import TimesFM200M

# Create a dummy historical series (e.g., 100 data points)
y = jnp.linspace(1.0, 10.0, 100, dtype=jnp.float32) + jnp.sin(jnp.arange(100) * 0.5)

2. Initialize the forecasting model

Import the desired model from chronax.models. We will use TimesFM200M, a large foundation model listed in the Chronax ecosystem.

# Initialize the model instance
model = TimesFM200M()
# TODO: confirm constructor arguments for TimesFM200M against the API

3. Fit the model to the historical data

Use the standard model.fit() method, passing only the target series y. Chronax handles the internal training loop and parameter optimization.

params, state = model.fit(y)

4. Generate the forecast

Use the model.predict() method, specifying the forecast horizon h. This method uses the fitted parameters and state to generate predictions.

h = 10  # Forecast 10 steps into the future
forecast_output = model.predict(params, state, h=h)

5. Extract the mean forecast

The predict method returns a dictionary containing various outputs. For deterministic models, the primary result is stored under the "mean" key.

mean_forecast = forecast_output["mean"]

print(f"Forecast shape: {mean_forecast.shape}")
print(f"First 5 forecast values: {mean_forecast[:5]}")

Full example

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

import jax.numpy as jnp
from chronax.models import TimesFM200M

# 1. Prepare the input data
y = jnp.linspace(1.0, 10.0, 100, dtype=jnp.float32) + jnp.sin(jnp.arange(100) * 0.5)

# 2. Initialize the forecasting model
model = TimesFM200M()
# TODO: confirm constructor arguments for TimesFM200M against the API

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

# 4. Generate the forecast
h = 10
forecast_output = model.predict(params, state, h=h)

# 5. Extract the mean forecast
mean_forecast = forecast_output["mean"]

print(f"Historical data length: {len(y)}")
print(f"Forecast horizon (h): {h}")
print(f"Mean forecast: {mean_forecast}")

Next steps

  • Learn how to add prediction intervals using the level argument in model.predict().
  • Explore using exogenous features (covariates) with models like TimesFM200M or Prophet.
  • Review the documentation for other foundation models like Chronos_base or Moirai_base.
  • Understand the structure of the params and state objects returned by model.fit().