Forecast demand
Goal: weekly unit sales per store for the next four weeks.
The query
FORECAST N TIMEFRAMES repeats the target window N times, back to back:
PREDICT SUM(sales.qty, 0, 7, days) FORECAST 4 TIMEFRAMES
FOR EACH stores.store_id
Timeframe 1 covers days (0, 7], timeframe 2 covers (7, 14], and so on.
Run it
ds = relativedb.from_dataframes(
{"stores": stores, "sales": sales},
links=[("sales", "store_id", "stores")])
df = ds.predict(query, anchor_time=t0)
The result has one row per store per timeframe. Forecasting routes to the regression checkpoint.
Notes
- The base window can be any unit:
SUM(usage.count, 0, 1, days) FORECAST 28 TIMEFRAMESgives a daily 4-week forecast. - Backtest by moving
anchor_timeinto the past; the engine guarantees each forecast only saw data available at that anchor. - A complete self-checking version lives at
examples/industry/bizops_demand_forecast.py.