Preserve the meaning of gaps
Choose a grid, missingness policy, and causal imputation rule without turning absent measurements into invented observations.
On this page
The question for today
What you’ll understand
- Distinguish zero, absent observation, and nonapplicable period.
- Compute a time-weighted summary of irregular measurements.
- Explain when interpolation introduces information from after the issue time.
A utilization sensor reports 20 percent at 10:00 and 80 percent at 10:10, with nothing between. A training notebook fills intermediate minutes with a straight line. At 10:05, however, the 10:10 endpoint did not exist in the forecasting system. The filled value of 50 percent reconstructs a smooth history using later evidence. Missingness handling therefore belongs inside the information contract. It also belongs inside the measurement contract: a silent counter, a closed facility, and an overloaded collector can produce identical empty cells while implying very different demand.
Define the grid and measurement type
First decide whether the process is modeled on elapsed physical time, local calendar slots, business periods, or event sequence. These grids answer different questions. A missing local hour during a daylight-saving transition is not the same as an unreported ordinary hour. Retain timezone-aware instants and define the business calendar separately. For a regular-grid model, construct the expected slots deliberately so an absent row becomes an explicit missing cell rather than silently compressing elapsed time.
Rates, counters, and interval totals require different aggregation. An instantaneous gauge can be averaged over observed samples, while a cumulative counter may need reset-aware differences. An interval count should be assigned to its covered interval, not treated as a continuous level merely because both are numbers. When holding a gauge constant between reports, state that assumption and cap how long it may remain valid. Otherwise a single stale reading can dominate an hour-long feature without any indication that observation support disappeared.
Keep absence visible to the model
A missing-value mask records whether a numeric input was actually observed. An age feature records time since its last eligible observation. Together they let the model distinguish a fresh zero from an old value carried forward. A fill value is an interface convenience, not evidence. Fit any learned replacement statistic on eligible training data only, and pass the mask through training and serving with the same convention. Do not let a real zero collide invisibly with the placeholder for missing.
Interpolation uses a structural assumption and, often, both neighboring endpoints. Linear interpolation is causal for a particular decision only after both endpoints are usable by that decision’s cutoff. It can be appropriate for reconstructing an older gap at a later origin while being illegal in a replay of the earlier decision. In pandas 2.3.3, the default linear method treats rows as equally spaced, whereas time interpolation uses time spacing. Neither option automatically enforces the forecasting system’s historical availability boundary.
Diagnose why observations disappear
Treat missingness as potentially informative. A collector may drop samples precisely when a host is overloaded; excluding those intervals can make measured utilization look artificially low. A sales series may be absent because an item was unavailable rather than because demand was zero. Include missingness patterns in regime reports, investigate operational causes, and distinguish a model input gap from an unavailable evaluation label. Each case changes a different part of the learning problem.
Compare candidate policies in a causal replay with deliberate outages of different durations. Measure accuracy, fallback frequency, feature age, and the fraction of targets that remain scoreable. A model that accepts arbitrarily stale filled values can look available while making untrustworthy predictions. Define a staleness threshold that changes behavior explicitly, such as serving a seasonal baseline or returning a degraded-quality flag. Version that policy with the model so an imputation change can be audited like any other deployment change.
Work it through
Two averages from the same irregular reports
A gauge is 2 units at minute 0 and 8 units at minute 1. The next observation occurs at minute 4 and is outside the interval [0,4). Assume each reading is held until the next report. Compute the time-weighted and sample averages over the first two readings.
The value 2 covers [0,1), lasting 1 minute. The value 8 covers [1,4), lasting 3 minutes. Both intervals are covered under the explicit hold assumption.
The time integral is 2×1+8×3=26 unit-minutes. Divide by the 4-minute interval to obtain a time-weighted mean of 6.5 units.
The arithmetic average of the two report values is (2+8)/2=5 units. It weights each report equally instead of weighting the durations represented by those reports.
The 1.5-unit difference is caused by weighting, not arithmetic error. Choose the summary that matches the measurement definition and preserve the assumption used between reports.
The living notebook
Explore the model
Interactive lab · waves
Unobserved points do not reveal a smooth path
Reset, set Phase difference to 0° and Amplitude ratio to 1. Predict resultant amplitude 2 and sum at x=0 of 0 initially, then approximately −0.959 after one Step at t=0.5 s. Reset, set Phase difference to 180° and Amplitude ratio to 1, then Step: predict cancellation and a sum near zero. This analytic two-wave model exposes different possible paths; it does not infer missing observations or run a forecasting model.
- Sum at x = 0
- 0.866
- Resultant amplitude
- 1.732
- Phase difference
- 60°
Two waves share the same frequency and wave number. Playback advances t in sin(2x − t) + a sin(2x − t + phase). 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 forFilling a gap requires assumptions about the path between observed points.
Pause & reason
Check your understanding
Your turn
Try it yourself
Readings at elapsed minutes 0 and 10 are 10 and 30 units. Compute the linear interpolation at minute 4. If the second reading becomes usable at minute 12, may an issue at minute 5 use that interpolation?
Take a moment to make a prediction or work it out on paper. Open a hint when you need one.
Give me a hint
Find the fraction 4/10 first, then apply the separate usable-time test.
Compare with the solution
The interpolated value is 10+(4/10)×20=18 units. An issue at minute 5 cannot use it because the second endpoint is not usable until minute 12. A later forecast can reconstruct the older gap under this interpolation assumption, while preserving that the filled point was never an actual measurement.
Keep the idea
Take it with you
- Match the time grid and aggregation to the measurement meaning.
- Expose missingness and age alongside numeric replacements.
- Two-sided interpolation must respect endpoint availability at each origin.
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.