Serve a forecast path with an explicit objective
Align direct and autoregressive multi-step models with masked supervision, known-future inputs, and versioned output semantics.
On this page
The question for today
What you’ll understand
- Distinguish direct, joint, and recursive forecasting.
- Compute a masked horizon-weighted training loss.
- Specify a serving response that preserves target and distribution meaning.
A reservation service needs demand estimates one, four, and twelve hours ahead. Training a strong one-hour model and repeatedly feeding its own predictions back may produce a very different twelve-hour system from a model trained directly on that target. Multi-horizon design determines the supervision, input contract, error propagation, and response shape. Decide whether the service needs conditional means, quantiles, or joint sample paths before selecting an architecture. Those outputs answer different operational questions, and a vector of individually sensible numbers does not automatically define a coherent distribution over the future.
Choose how horizons share computation
A direct method predicts a particular horizon from the origin’s information; separate direct models can specialize but duplicate work. A joint multi-output method predicts several horizons together, potentially sharing an encoder. A recursive method repeatedly applies a one-step transition, consuming its own generated outcomes after the first step. Training with observed previous outcomes and serving with generated ones creates a distribution shift that must be evaluated through complete forecast rollouts rather than teacher-forced one-step losses alone.
DeepAR provides an autoregressive probabilistic construction, while Temporal Fusion Transformers illustrate direct multi-horizon quantile forecasting with distinct input roles. These are examples of design choices, not guarantees that one architecture wins on every workload. For any model, separate static metadata, observations available only through the issue origin, and genuinely future-known covariates. Weather observations from tomorrow are not interchangeable with today’s weather forecast for tomorrow. Preserve the vintage of the latter when it is used as a predictor.
Match the output to the decision loss
Squared-error minimization targets a conditional mean under the usual finite-second-moment population interpretation. Absolute error targets a conditional median, and pinball loss targets a specified conditional quantile. If under-reserving capacity is more costly than over-reserving, a higher quantile may be useful, but its probability level should follow a stated decision cost model. Do not label a median as expected demand or add medians across services as though they were additive expectations.
Separate per-horizon weighting from per-example weighting. Long horizons may have fewer mature labels, and a global normalization over active entries can then give short horizons more effective influence. If the objective is an equal average of horizon-specific risks, compute those risks with their own denominators before combining them. Quantile models also need checks for crossing outputs and calibration by horizon. Reordering quantiles may repair ordering but changes the deployed prediction rule and must itself be evaluated.
Publish a complete path contract
Return issue timestamp, ordered target intervals, horizon convention, units, model and feature versions, and output type. If a horizon is unsupported, reject it or expose a documented interpolation policy; silently mapping twelve hours to the nearest trained horizon changes the question. For probabilistic samples, preserve path identity across horizons so a downstream planner can evaluate aggregate demand and temporal peaks under the model’s joint dependence assumptions.
Do not treat independent marginal quantiles as a joint scenario. Summing a ninety-fifth percentile at each hour does not generally produce the ninety-fifth percentile of total demand. A planner needs either a valid joint construction or an explicit conservative approximation. Exercise serving with partial horizon masks, missing future-known features, and artifact changes while a request is in flight. The response should be internally version-consistent even when a new model is promoted halfway through computation.
Work it through
Normalize only the available weighted errors
One training example has squared errors 4, 9, and 16 at horizons 1, 4, and 12. Their weights are 1, 2, and 1. Only the first two labels are mature. Compute the masked objective, then compute a q=0.9 pinball loss for actual 12 and predicted quantile 10.
The availability mask is (1,1,0). Active weighted squared error is 1×4+2×9=22; the unavailable third error contributes nothing and must not be evaluated from a missing numeric value.
Active weight is 1+2=3, so the example’s masked objective is 22/3≈7.333 target-units squared. Dividing by all four configured weight units would incorrectly dilute it to 5.5.
For the quantile example, residual u=12−10=2 is positive. Pinball loss is q×u=0.9×2=1.8 target units; underprediction receives the larger coefficient at this quantile.
Availability masks affect both numerator and denominator. Output statistics also require their own correctly interpreted losses rather than sharing an ambiguous accuracy label.
The living notebook
Explore the model
Interactive lab · markov
Compare predictions at multiple horizons
Reset, set Transition p · 0 → 1 to 0.2 and Transition q · 1 → 0 to 0.3. Predict P(state 1)=0.2 after one Step and 0.3 after two Steps; the stationary probability is 0.4. Reset, explicitly set p=0.4 and q=0.6, then Step: predict 0.4 after one transition and thereafter. This is an exact two-state distribution from initial state 0, not a trained demand model or sampled scenario generator.
- P(state 1) at step 0
- 0%
- Stationary P(state 1)
- 60%
- Chain behavior
- Monotone convergence
Exact finite-step probabilities for a two-state chain starting in state 0, not sampled trajectories. Playback advances two transitions per second. When p = q = 0 every distribution is stationary; when p = q = 1 the chain alternates forever. A single zero transition creates an absorbing state. Parameter changes pause playback and recompute the model at the current elapsed time. Reset restores both parameters and returns time to zero. Playback starts paused. Adjust either parameter, then choose Play or Step.
Look forA horizon is part of a prediction’s meaning, even when model parameters stay fixed.
Pause & reason
Check your understanding
Your turn
Try it yourself
A q=0.8 forecast predicts 15 units but the actual is 10. Compute its pinball loss. Separately, two hours each have a marginal 0.9 quantile of 20 units: can their sum 40 be called the 0.9 quantile of total two-hour demand without a dependence model?
Take a moment to make a prediction or work it out on paper. Open a hint when you need one.
Give me a hint
The residual is negative; use q−1 for that branch. A quantile of a sum depends on the joint distribution.
Compare with the solution
Residual is −5, so loss is (0.8−1)×(−5)=1 unit. The two marginal quantiles sum to 40, but that is not generally the total’s 0.9 quantile. A justified joint distribution, joint forecast samples, or an explicitly stated approximation is needed to attach a probability interpretation to the aggregate.
Keep the idea
Take it with you
- Choose direct or recursive semantics and test the complete rollout.
- Mask unavailable labels in both loss sums and denominators.
- Distinguish marginal forecasts from joint future paths.
Read further
Original sources and deeper explanations to follow at your own pace.
Optional progress, saved in this browser when available. Revisit any lesson at any time.
Lesson not marked complete.