Skip to navigation

Run Kumo Forecast

View as MarkdownOpen in Claude
Runs in Kumo-TS

Kumo Forecast is part of the Kumo-TS library, not SDM. Install the Kumo-Forecast package before running the example.

Use perform_forecasting to predict future values of a series from its history. For what the model is and how it works, see Kumo Forecast.

PropertyValue
Entry pointperform_forecasting(df, config=ForecastingConfig(...), context_df=None)
PackageKumo-TS Kumo-Forecast 1.0.1, Python 3.10 or later
InputA pandas DataFrame with a timestamp column, a target column, and optional numeric covariates
OutputA DataFrame with future timestamps and a <target>_forecast column
DevicesCUDA, Apple MPS, or CPU, chosen automatically

Shape Your Data

  • timestamp_column: evenly spaced timestamps. The forecast continues at the same frequency.
  • target_column: the series to forecast.
  • Other numeric columns are used as covariates automatically.
  • Provide at least seq_len rows (default 512).
  • Cross-channel attention between the target and covariates is on by default (use_cross_channel=True).

Example

Run this script with uv run from the Kumo-TS/Kumo-Forecast directory. The first run downloads the Kumo checkpoint into the working directory and the MOMENT backbone into the Hugging Face cache.

import numpy as np
import pandas as pd
from sdk.forecasting import ForecastingConfig, perform_forecasting
hours = 600 # at least seq_len (512) rows of history
t = np.arange(hours)
noise = np.random.default_rng(0).normal(scale=2.0, size=hours)
df = pd.DataFrame({
"timestamp": pd.date_range("2025-01-01", periods=hours, freq="h"),
"load": 100 + 20 * np.sin(2 * np.pi * t / 24) + noise,
})
config = ForecastingConfig(
timestamp_column="timestamp",
target_column="load",
forecast_horizon=72,
)
if __name__ == "__main__": # required: Kumo-TS starts worker processes
forecast = perform_forecasting(df=df, config=config)
print(forecast.shape)
print(forecast.head(3))
Expected output
(72, 2)
timestamp load_forecast
0 2025-01-26 00:00:00 99.367668
1 2025-01-26 01:00:00 104.370789
2 2025-01-26 02:00:00 109.090034

The output has one row per forecast hour, continuing the input timestamps. Forecast values can differ slightly across devices. With an empty cache, the first run downloads the Kumo checkpoint (about 1.4 GB) and the MOMENT backbone (also about 1.4 GB).

Use a main guard in scripts

Kumo-Forecast loads data in worker processes. On macOS and Windows, those workers import your script again, so keep the model call under if __name__ == "__main__":. Without it, DARR fails with DataLoader worker ... exited unexpectedly.

Retrieval from History (DARR)

Pass an archive of past data as context_df to blend the continuations of similar past windows into the forecast. alpha weights the direct forecast (alpha * direct + (1 - alpha) * retrieved; default 0.01), k sets the number of neighbors (default 64), and temperature sets how sharply they are weighted (default 0.05).

Match the retrieval stride to your seasonality

Archive windows are indexed every context_stride rows, which defaults to the 72-step model horizon. For hourly data with a daily cycle, every window then ends at the same hour of day, and retrieved continuations are out of phase with the forecast. Set context_stride=1, or a value that is not a multiple of your cycle length. In a synthetic hourly test, this cut the retrieval-only error from 23.87 to 9.52 MAE.

Explain a Forecast

Kumo Forecast shows how much weight the model assigns to recent history at each forecast step. When the input includes multiple series, it also reports their relative contributions.

To see which lookback lengths receive the most weight for each forecast hour in the example above, run the load series with interpretability=True.

from sdk.forecasting import ForecastingConfig, perform_forecasting
if __name__ == "__main__":
config = ForecastingConfig(
timestamp_column="timestamp",
target_column="load",
forecast_horizon=72,
interpretability=True,
interpretability_run_name="load_forecast",
)
forecast = perform_forecasting(df=df, config=config)

When matplotlib is installed, this code generates a PDF report with a lag attribution heatmap and saves it to interpretability_output/load_forecast/explanation_report.pdf. See the interpretability reference for the JSON and CSV outputs.

Inputs and Limits

  • At least seq_len rows; fewer raises DataFrame has N rows but seq_len requires at least 512 rows.
  • Missing target values are filled with zeros.
  • For DARR, context_df needs the same timestamp and target columns, at least one shared covariate, and at least seq_len + max(72, forecast_horizon) rows. Set context_stride to match your seasonality (see above).
  • DARR does not always beat the direct forecast. Compare both on a held-out window of your own data.
  • Weight files are written to the paths in standardizer_pkl and ckpt, which default to the working directory.

Fine-Tuning

Fine-tune on your own CSV with examples/finetune_example.py.

Learn More