AI & Machine Learning Master Course — 141. Time-indexed data and forecast definitions
Smartyfy AI & Machine Learning Master Course
Course ID: smartyfy-ai-ml-master-200
Lesson 141: Time-indexed data and forecast definitions
Prerequisites: Lesson 140. Learning outcome: Specify horizons, frequency, issue times, and available information.
Define the forecast before choosing a model
A forecast is a prediction made at a specified issue time for a specified future target. “Predict demand” leaves several essential questions unanswered: demand for which item or location, over what interval, in what units, and using information available at what moment?
Suppose a fictional warehouse issues a daily forecast at the beginning of a planning period. The target might be units requested during a later day, not cumulative sales since the start of the month. A forecast for a day and a forecast for the next seven-day total are different targets even if both use the same raw records.
Write a forecast contract containing the series key, time index, target definition, issue time, horizon, update frequency, and data-availability rules. This contract determines what a valid training example looks like and what a deployment evaluation must reproduce. A sophisticated model cannot repair a target whose timing is ambiguous.
Event time is not necessarily availability time
An observation has an event period describing when the measured activity occurred. It may also have a publication or availability time describing when the forecasting system could actually use it. Late reports, batch processing, and revisions can separate those times.
A backtest must use the version and values available at each historical issue time. Loading the latest complete table and filtering only by event date can expose revised or late-arriving values that the forecaster would not have known. An as-of dataset records that information boundary explicitly.
Features known in advance, such as a planned closure or calendar day, may legitimately describe the target period. Features learned only afterward, such as realized target-day weather or final demand, may not. A forecast of future weather is a different input from the future weather that actually occurred; distinguish them in the data lineage.
Frequency, aggregation, and missing periods matter
A regular time series has an intended interval such as hour, day, or month. Missing rows should not automatically be interpreted as zero activity. A missing measurement, an actual zero, and a period when the process was not operating can have different meanings.
Aggregation defines the target’s units. Summing hourly demand gives daily volume, while averaging temperatures gives a different type of summary. A simple average of rates may be wrong when denominators vary; retain the quantities needed for an appropriate weighted calculation.
For timestamped real data, document time zone and boundary conventions. Calendar days can differ from fixed twenty-four-hour windows. The lab avoids calendar and daylight-saving complications by using integer periods, but that simplification should not be mistaken for a complete timestamp policy.
CPU lab: enforce a publication delay
Four fictional records describe periods zero through three. Each becomes available one period later. At issue period three, the latest usable observation is period two with value fifteen. The period-three value ninety is not available until period four and must be excluded.
The target is period five. Under the lab’s explicit definition, horizon equals target period minus issue period, so it is two. The gap from the latest known observation at period two to the target is three periods. Both numbers are correct, but they describe different reference points.
The naive forecast repeats the latest available value, fifteen. Assertions verify the availability filter and exclusion of the late record. This is a data-contract demonstration, not a claim that persistence is the best forecast. There are no downloaded records, external calendars, or fitted models.
# Integer periods with explicit publication delay; fictional values.
records=[{'period':0,'available':1,'value':10},
{'period':1,'available':2,'value':12},
{'period':2,'available':3,'value':15},
{'period':3,'available':4,'value':90}]
issue=3; target=5
visible=[r for r in records if r['available']<=issue and r['period']<target]
latest=max(visible,key=lambda r:r['period'])
forecast=latest['value']
print('Issue / target / horizon:',issue,target,target-issue)
print('Latest available observation:',latest['period'],latest['value'])
print('Gap from latest observation to target:',target-latest['period'])
print('Naive forecast:',forecast)
assert forecast==15 and all(r['available']<=issue for r in visible)
assert records[-1] not in visible
Construct evaluation rows from historical information sets
Each forecast row should retain issue time, target time, prediction, eventual outcome, and relevant model or data version. Several forecasts can target the same future period from different origins. They are different forecasting decisions and may have different horizons.
Decide when outcomes become eligible for scoring. A target may have occurred but not yet been reported, so an immediate accuracy dashboard can be incomplete or biased toward fast-arriving labels. Track maturity and missingness rather than interpreting unreported outcomes as correct forecasts or zeros.
For training, include only examples whose targets would already be known at the chosen fitting cutoff. A feature can be historical while its label is still unavailable. This distinction matters especially when training rows predict long horizons or targets are revised later.
Finally, preserve a simple baseline under the same contract. If a learned model uses fresher data than the baseline or predicts a different aggregation interval, their scores do not isolate modeling quality. Compare the same issue times, target periods, and availability rules before comparing algorithms.
Four practice questions with worked answers
Practice 1
Issue period is 10 and target period is 13. Under target-minus-issue notation, what is the horizon?
Answer: The horizon is three periods. State the period units and issue convention so the number cannot be confused with three observations or three calendar days under another index.
Practice 2
A period-nine measurement is first published at period eleven. May an issue-period-ten forecast use it?
Answer: No. Its event period is historical, but it was not yet available. The availability cutoff, not event date alone, determines whether it belongs to that forecast’s information set.
Practice 3
Why are horizon two and observation-to-target gap three both correct in the lab?
Answer: The issue is period three and target is five, giving horizon two. The latest available observation is period two, giving a three-period gap to the target. Publication delay separates those reference points.
Practice 4
A daily row is missing. What should happen before filling it with zero?
Answer: Investigate whether it represents zero activity, a missing report, or a non-operating period. Apply a documented rule appropriate to the target rather than silently changing missingness into observed demand.
Five multiple-choice questions
Question 1
Which timestamp determines whether a record can be used at an issue time?
- A. Its actual availability time under the evaluation contract.
- B. Only its event date, regardless of reporting delay.
- C. The date when the final backtest file was downloaded.
Correct: A. Information must have been available when the forecast was issued. Historical event labels alone do not establish that.
Question 2
What is the lab’s latest usable value at issue three?
- A. 90 from period three.
- B. 15 from period two.
- C. The average including every record in the completed table.
Correct: B. The ninety-valued record is not published until period four. The latest available observation is therefore fifteen.
Question 3
Which future-period feature can be legitimate?
- A. A calendar property already known when the forecast is issued.
- B. A revised measurement released after the forecast deadline.
- C. The final realized target value recorded after the period ends.
Correct: A. Future reference does not imply leakage when the information is genuinely known in advance. Later realized or revised values are unavailable.
Question 4
Why retain both issue and target times?
- A. Each target can have only one valid forecast in its entire history.
- B. Issue time is always identical to the latest observed event time.
- C. The same target can be forecast from several origins with different horizons.
Correct: C. Multiple decision times create distinct forecast tasks. Publication delays also make issue and latest observation times differ.
Question 5
What is required for a fair baseline comparison?
- A. Allowing the learned model to use final revised values while the baseline uses historical releases.
- B. The same target, issue schedule, and information availability.
- C. Only the same number of model parameters.
Correct: B. Comparable information and target definitions are essential. Parameter counts alone cannot compensate for timing advantages or leakage.
Common pitfalls
Avoid equating event time with availability, filling missing periods with zeros by habit, mixing horizons defined from different origins, and scoring immature outcomes as if labels were complete. Make the forecast contract explicit.
Summary
Forecasting begins with a precise target and historical information boundary. Issue time, target time, observation availability, aggregation, and outcome maturity determine whether both training and evaluation describe a real forecasting decision.