Part III — Advanced Systems · Chapter 18 · Lesson 6 of 7 · 8 min read
Lesson 6: Grouped Forecasts, Confidence Bands, and Chart-Ready Output
Lesson level: Advanced
Purpose: Produce forecasts for many series at once, express their uncertainty as bands that users can act on, keep totals consistent across levels, and deliver results in a stable, chart-ready format.
Learning objectives
By the end of this lesson you will be able to:
- run a forecasting method per group with isolated failures and per-group method selection
- handle short, new, and intermittent series
- build prediction intervals from backtest residuals
- check interval coverage and explain what it means
- reconcile forecasts across levels such as product, store, and region
- publish forecasts in a long, versioned, chart-ready schema
6.1 Forecasting many series
A grouped forecast applies a fit and predict pair to each series independently. At scale, three engineering concerns dominate:
- Isolation. One bad series must not stop the run. Catch failures per group, record the reason, and fall back to a simpler method.
- Determinism. The same inputs and configuration must produce the same outputs. Sort groups, fix random seeds, and record method versions.
- Selection. The best method can differ by group. Choose per group from the backtest leaderboard of Lesson 5, with a default for groups too short to backtest.
Illustrative listing.
def forecast_group(key, series, horizon, methods, default="seasonal_naive"):
try:
if series.height < 8 * 7:
name = default
else:
name = choose_method(series, methods) # from backtest results
model = methods[name].fit(series)
values = methods[name].predict(model, horizon)
return {"key": key, "method": name, "values": values, "error": None}
except Exception as exc:
fallback = methods[default]
values = fallback.predict(fallback.fit(series), horizon)
return {"key": key, "method": default, "values": values,
"error": type(exc).__name__}
results = [forecast_group(k, g, 28, METHODS)
for k, g in sorted(panel.group_by("store_id"))]
Keep the error column in the output. A dashboard that shows which groups fell back, and why, prevents silent degradation: a run in which 30% of series fell back is a run someone should look at, even if every number looks plausible.
6.2 Short, new, and intermittent series
- Short series cannot support seasonal methods. Use a naive or SES forecast, or borrow the seasonal pattern from a parent group such as the product category or region.
- New items have no history at all. Forecast from analogous items, or from the parent group scaled by an initial share, and switch to the item's own history once enough has accumulated.
- Intermittent series — many zeros with occasional demand, common for slow-moving parts — break percentage metrics and most smoothing methods. Forecast the demand size and the interval between demands separately (the idea behind Croston-type methods), and evaluate with scaled or absolute metrics.
6.3 Prediction intervals from backtest residuals
A point forecast says "about 420 orders". A prediction interval says "between 360 and 490 orders, with 80% probability". Planners need the interval: safety stock, staffing buffers, and capacity limits are all set from the upper or lower band, not from the middle.
Strictly, a confidence interval describes uncertainty in an estimated parameter, and a prediction interval describes where a future observation is likely to fall. Business users often say "confidence band" for both; in forecast output, label the bands as prediction intervals and state the coverage level.
The most practical method for baselines uses the empirical errors from the backtest. For each horizon h, collect the errors from all origins, take their quantiles, and add them to the point forecast. Because errors usually grow with the horizon, quantiles must be computed per horizon.
Illustrative listing.
def interval_offsets(backtest, levels=(0.1, 0.9)):
# backtest has columns: horizon, actual, forecast
errors = backtest.with_column("e", col("actual") - col("forecast"))
return errors.group_by("horizon").agg(
lo = col("e").quantile(levels[0]),
hi = col("e").quantile(levels[1]),
n = col("e").count())
bands = (forecast
.join(interval_offsets(bt), on="horizon", how="left")
.with_column("lower", (col("point") + col("lo")).clip(lower=0))
.with_column("upper", col("point") + col("hi")))
This method makes no distributional assumption, captures bias (the interval is asymmetric if errors are), and is easy to explain. It needs enough backtest errors per horizon — at least about 30 is a reasonable working minimum — and it assumes future errors resemble past errors. Clip lower bounds at zero for quantities that cannot be negative, and note that clipping slightly changes coverage.
Model-based intervals, such as those derived from the error variance of an exponential-smoothing model, are an alternative. They are elegant but rely on assumptions — normal, independent errors — that business data often violates. Whichever method you use, verify it empirically, as described next.
6.4 Checking coverage
An 80% interval is honest only if about 80% of actual values fall inside it in out-of-sample tests. Measure coverage on a later backtest window than the one used to compute the offsets:
- Coverage well below the nominal level means the bands are too narrow — users will be surprised too often.
- Coverage well above it means the bands are too wide — users will over-buffer and waste money.
- Check coverage per horizon and per segment. Overall coverage can look right while high-volume stores are under-covered and small ones over-covered.
Also report the average interval width. Two methods with the same coverage are not equal: the narrower one is more useful. Coverage and width together are the interval equivalent of bias and error for point forecasts.
6.5 Reconciling across levels
Forecasts are usually needed at several levels: item, store, region, total. If each level is forecast independently, the store forecasts will not sum to the region forecast, and planners at different levels will disagree. Reconciliation makes the levels coherent:
- Bottom-up: forecast the lowest level and sum upward. Coherent by construction and preserves local detail, but low-level series are noisy.
- Top-down: forecast the total and split it by historical or forecast proportions. Stable, but loses local patterns.
- Middle-out: forecast an intermediate level, sum up, and split down.
- Optimal combination: forecast all levels, then adjust them jointly to be coherent while staying close to every original forecast. Usually most accurate, but more complex.
Prediction intervals do not add up like point forecasts: the 90th percentile of a total is less than the sum of the 90th percentiles of its parts, because not every part has a bad day at once. Compute intervals for aggregates from aggregated backtest errors, not by summing lower and upper bounds.
6.6 Chart-ready output
Dashboards and reports consume forecasts more reliably when the output follows a fixed, long schema: one row per series, date, and value type. Long data is easy to filter, plot as overlaid lines and bands, and extend with new methods without changing columns.
| Column | Type | Meaning |
|---|---|---|
| run_id | string | Identifier of the forecast run |
| generated_at | timestamp (UTC) | When the run produced the forecast |
| origin_date | date | Last date of data used |
| series_key | string | Group identifier, for example store or product |
| level | string | Hierarchy level: item, store, region, total |
| date | date | Date being described |
| horizon | integer | Periods after the origin; 0 or null for actuals |
| kind | string | actual, point, lower, or upper |
| value | float | The number |
| interval_level | float | Nominal coverage for bands, for example 0.8 |
| method | string | Method name and version |
| status | string | ok, fallback, or failed, with reason |
Include recent actuals in the same table so that a chart can draw history and forecast together without a second query. Write each run as an immutable, versioned batch; never overwrite a previous run. Keeping old runs lets you measure accuracy after the fact and explain why a plan was made from the numbers available at the time.
Write the output with the data layer's writer to the agreed format — for example CSV or JSONL for interchange, or a database table through the SQLite reference backend from Chapter 17 — and validate it against the schema before publishing.
Common mistakes
- Letting one series fail the run: isolate failures and fall back per group.
- Forcing seasonal methods on short series: use simpler methods or borrow parent patterns.
- Using one interval width for all horizons: errors grow with horizon; compute bands per horizon.
- Never checking coverage: an untested 80% band may cover 55% in reality.
- Summing interval bounds: aggregate bands must come from aggregate errors.
- Incoherent levels: reconcile so that store, region, and total plans agree.
- Overwriting previous runs: keep versioned, immutable outputs for audit and accuracy tracking.
Guided practice
- Run a grouped seasonal naive forecast for 20 stores, deliberately corrupting one store's data. Confirm that the run completes and the failure is reported.
- Compute 80% empirical bands per horizon and measure coverage on a later window. Is it close to 80%?
- Forecast stores and their region independently, then reconcile bottom-up. How much does the region forecast change?
Hands-on lab: A grouped forecast with bands
- Use the store panel from Lesson 3 and the per-store method choices from the Lesson 5 leaderboard.
- Forecast 28 days for every store with failure isolation and fall-backs.
- Compute 80% and 95% bands per horizon from backtest errors, clip at zero, and measure coverage on a held-back window.
- Reconcile bottom-up to region and total. Compute aggregate bands from aggregate backtest errors.
- Write the output in the long schema of Section 6.6, including the last 56 days of actuals, and validate it before writing.
Review questions
- Why must failures be isolated per group in a grouped forecast?
- How should a forecast be produced for a brand-new item?
- How are empirical prediction intervals built from backtest errors?
- What do coverage and width each tell you about an interval?
- Why can interval bounds not simply be summed across groups?
- Why is a long, versioned output schema preferable for dashboards?
Applied challenge
A distributor forecasts 3,000 products across 12 warehouses. Planners order at warehouse level, finance budgets at the national total, and many products sell only a few units a month. Design the full grouped forecasting pipeline: method selection rules, handling of new and intermittent items, interval method and coverage targets, reconciliation strategy, output schema, and run-health reporting. Implement it on a 100-product sample and report coverage and accuracy by level.
Lesson summary
Production forecasting is grouped forecasting: isolate failures, choose methods per group, and treat short, new, and intermittent series specially. Express uncertainty with prediction intervals built per horizon and verified by coverage and width. Reconcile across levels so that plans agree, and publish versioned results in a long, validated, chart-ready schema.
Lesson status: Ready for review.