Skip to content
AI.info

ML data engineering

Time-Series and Sequential Data Engineering

Engineer histories, horizons, gaps, revisions, panels, windows, and backtests for ordered data.

By the end you can

Time series are ordered measurement systems, not ordinary rows with dates

A temporal dataset has several interacting clocks: when the event occurred, when it was observed, when a forecast is issued, and when the target becomes measurable. Cadence matters. Sensor readings may be irregular. Sales may be daily but corrected later. Forecasts may run hourly with several future horizons, and resampling can create values that never existed at decision time. Sequential examples also overlap. Two adjacent windows can share most of their history and outcomes, which makes random row splits especially misleading.

The scale at which this has to be got right is not hypothetical. One sepsis challenge required a prediction at every hourly time window across 40,336 patient records, released publicly from two hospital systems, with 22,761 records from three systems sequestered. That is more than 2.5 million hourly time windows and more than 15 million data points between them. That was PhysioNet's 2019 sepsis challenge. Every one of those windows is an example, and its history, its horizon and its label maturity had to be fixed in writing before a single model was fitted.

Data engineering must preserve order, revisions, gaps, and availability. The table should reconstruct what the forecasting or sequence system would have known at each origin.

A timestamp column does not make a dataset temporally correct; the build must preserve information flow through time.

Case

What 100,000 series told the M4 competition

The M4 competition is the largest public test of how to choose a forecasting method: 100,000 time series, 61 forecasting methods, every method scored on all of them. It was reported twice in the International Journal of Forecasting by the same three authors, once on the design and once on the findings. The findings paper lists five.

Twelve of the 17 most accurate methods were combinations of mostly statistical approaches. The winner was a hybrid using both statistical and machine-learning features, whose “average sMAPE was close to 10% more accurate than the combination benchmark used to compare the submitted methods”. Six entries were pure machine learning. On those, the authors' own summary is blunt: “the six pure ML methods performed poorly, with none of them being more accurate than the combination benchmark”.

Every method was scored on all 100,000 series, so this is not a result about one domain or one cadence. It is a result about how much of forecasting accuracy is decided before the model class is chosen — in the construction of the series, the origins and the benchmark.

Figure

M4 in one row of squares: 12 of the 17 most accurate methods were combinations, and none of the six pure machine-learning entries beat the combination benchmark.

Example

Temporal leakage beyond obvious future columns

Each example uses values that only became available after its forecast origin. The gap between what production saw and what the archive now holds is measurable, and one agency measures it on itself. The U.S. Bureau of Economic Analysis publishes reliability tables for GDP vintages. Over 1996-2024 the mean absolute revision to annualised real GDP growth was 0.5 percentage point from the advance estimate to the second, and 0.6 percentage point from the advance to the third. From the second estimate to the third it was 0.3 percentage point. Of the first of those the agency writes that “"Advance" estimates are released near the end of the first month following the end of the quarter and are based on source data that are incomplete or subject to further revision by the source agency.”

The same revisions have been measured on a different vintage archive. Lubik and Titcomb, in a Federal Reserve Bank of Richmond economic brief, put the mean advance-to-final revision on Philadelphia Fed vintages at 0.45 percentage point, with a standard deviation of 1.97 percentage points. Policymakers, they note, act “based on the data available, not necessarily knowing the final readings”. A backtest fed the final series hands the model exactly that advantage, every quarter.

  • Centered smoothing: a seven-day centered average includes three days after the prediction date.
  • Revised economic data: training uses the final published series while production saw the advance estimate. That estimate differs from the third by 0.6 percentage point on average over 1996-2024, and from the final value by 0.45 percentage point on Philadelphia Fed vintages, with a standard deviation of 1.97 percentage points.
  • Global normalization: mean and variance are estimated using future years before evaluating earlier periods.
  • Stockout correction: historical demand is reconstructed using later inventory audits unavailable at forecast time.
  • Overlapping targets: random splitting places near-identical history windows and shared outcome periods across train and test. Where one row is one hour, consecutive examples for the same entity differ by a single hour of history.

Visual

A forecasting example has an origin, history, horizon, and publication state

Each boundary determines which observations and targets belong to one example. PhysioNet's 2019 sepsis challenge is worth reading less as a benchmark than as a specification, because it fixed those boundaries explicitly and in public.

History and origin: a prediction was required at every hourly time window, and PhysioNet states that “each row will represent a single hour's worth of data”. The origin therefore advances one row at a time. The observation history is everything above the current row.

Outcome horizon: the challenge paper puts it in one sentence. “In particular, we asked participants to predict sepsis at least 6 hours but no more than 12 hours before the onset of sepsis according to Sepsis-3 clinical criteria”, its nine authors write. The horizon is a stated interval, not a vague notion of earliness.

Label maturity: onset was not left to a chart note. It was defined by two clocks — t_suspicion, from antibiotics and cultures, and t_SOFA, from a two-point SOFA rise within 24 hours. The scoring window rewarded predictions between 12 hours before and 3 hours after t_sepsis.

That specification produced 40,336 public records from two hospital systems and 22,761 sequestered records from three, spanning “over 2.5 million hourly time windows and over 15 million data points”. Four of the five boundaries in the diagram are written into its rules. Known-future inputs are the one an intensive-care setting supplies least of, which is itself a fact about the domain rather than an oversight.

FigureProcess · 5 steps
  1. 1. Observation history

    Measurements and covariates available before the forecast origin.

  2. 2. Forecast origin

    The precise time when the system would issue a prediction.

  3. 3. Known-future inputs

    Calendar, plan, price, or schedule information legitimately available for future periods.

  4. 4. Outcome horizon

    The future interval the model is asked to predict.

  5. 5. Label maturity

    The delay after which outcomes and revisions are stable enough for evaluation.

The forecast origin is the temporal equivalent of the prediction cutoff in ordinary supervised learning — in the 2019 sepsis challenge that cutoff moved one row, one hour, at a time.

Comparison

Wide panels, long event tables, and windowed tensors

These representations serve different pipeline stages and should preserve the same temporal semantics. Two PhysioNet challenges show the first two shapes side by side, on the same kind of clinical stream.

The 2012 data arrives as irregular events. Its 36 time-series variables, PhysioNet notes, “may be recorded at regular intervals ranging from hourly to daily, or at irregular intervals as required”. That is the long event table in its natural state: flexible, honest about when nothing was measured, and useless to a model until it is pivoted.

The 2019 data arrives already regularised into a panel, one row per patient per hour. Windowing that panel for a sequence architecture is what turns 40,336 records into more than 2.5 million hourly time windows. That multiplication is the whole point of the third column. Adjacent windows repeat nearly all of their history, so the tensor has to carry source indices back to record and hour, or the split can no longer be controlled.

FigureComparison · 3 columns

Long event table

One row per entity, timestamp, variable, or event.

  • Flexible for irregular observations and new variables
  • Requires careful pivoting and duplicate policy
  • Natural landing format for telemetry
  • Example: machine sensor events

Regular panel table

One row per entity and cadence with fixed columns.

  • Convenient for lags and many forecasting models
  • Needs resampling and gap semantics
  • Can hide whether a value was observed or filled
  • Example: daily product-store demand

Windowed sequence tensor

Materialized history and target arrays for model input.

  • Efficient for training sequence architectures
  • Can duplicate overlapping periods heavily
  • Needs source indices for audit and split control
  • Example: 168 hourly steps predicting next 24 hours

Key idea

A filled gap is not an observation

Forward fill, interpolation, and zero fill create values where the source did not report one. Preserve an observed-versus-filled indicator and the age of the last real measurement. The correct fill depends on the variable. Forward fill may make sense for a configuration state, and it can be dangerously wrong for flow, demand, or a rapidly changing vital sign. Long gaps may require exclusion, fallback, or a separate missing-sequence model. Uniform resampling should not disguise sensor outages or business closures.

PhysioNet's 2012 ICU challenge shows what the raw material looks like before anyone fills it. “The data used for the challenge consist of records from 12,000 ICU stays”, drawn from MIMIC II v2.6. They were selected at random from the 12,753 patients aged 16 or over whose first ICU stay lasted at least 48 hours. Those 12,000 were then split at random into three groups of 4,000: training set A, open test set B, hidden test set C. Each record covers the first 48 hours of that first stay, with 5 general descriptors and 36 time-series variables. The challenge paper describes the coverage plainly: “Up to 41 variables were recorded at least once during the first 48 hours after admission to the ICU. Not all variables were available in all cases.” PhysioNet repeats the warning on the dataset page — “Not all variables are available in all cases, however.”

Resample that onto an hourly grid and every one of those absences becomes a number that no clinician ever measured. Nothing in the resampled table distinguishes a patient whose lactate was checked twice from a patient whose lactate was never checked at all. Only a pipeline built to keep that distinction can tell them apart.

Regular cadence is a representation choice; it must retain the evidence that observations were missing or synthesized.

Steps

Build temporal examples from forecast origins

Generate examples by simulating the production schedule across history. The 2019 sepsis challenge is a worked instance of the first, second and fourth steps at once. The cadence is hourly. The origin is every hourly time window. The targets are defined by t_suspicion and t_SOFA rather than by whoever wrote the discharge summary. Maturity and horizon sit inside the metric itself: the scoring rule is a utility function that “rewards early sepsis predictions and penalizes late or missed predictions and false alarms”.

The steps that remain yours are the third and the fifth. Bounded features have to stop at the origin, even when the tooling makes it easy to reach past it. Chronological backtesting has to reproduce the retraining cadence rather than a single split. M4 is the reason to spend the effort there rather than on the model class. Sixty-one methods were scored on 100,000 series. Twelve of the 17 most accurate were combinations of mostly statistical approaches, and no pure machine-learning entry beat the combination benchmark.

FigureProcess · 5 steps
  1. 1. Define cadence and origin

    State when predictions run, for which entities, and under which time zone or calendar.

  2. 2. Freeze available history

    Select measurements and revisions visible by each origin.

  3. 3. Create bounded features

    Compute lags, rolling windows, seasonality, and known-future inputs without crossing the origin.

  4. 4. Assign horizons and maturity

    Create targets only after the full outcome and revision window is observable.

  5. 5. Backtest chronologically

    Use rolling or expanding origins with gaps that reflect retraining and deployment.

A temporal dataset should be reproducible as a sequence of historical production runs.

Analogy

Backtesting replays the forecast, not the archive

A forecast made last March has to be judged on last March's information. You must use the observations, instruments, and forecast models available on each historical morning, not the cleaned climate archive assembled years later. The forecast origin is that morning.

The archive in that analogy is a real object, and it is explicit about what it is. ERA5 is ECMWF's reanalysis of the global atmosphere from 1940 to the present, and it is produced with one fixed version of the forecasting system throughout. ECMWF said so in its own newsletter in 2019: “ERA5 is based on 4D-Var data assimilation using Cycle 41r2 of the Integrated Forecasting System (IFS), which was operational at ECMWF in 2016”. The NCAR/UCAR Climate Data Guide is more precise about how brief that operational window was: “ERA5 is a product of the Integrated Forecast System (IFS) release 41r2, which was operational at ECMWF during the period March-November 2016”. The output is hourly, at 31 km horizontal resolution on 137 vertical levels, against 79 km for ERA-Interim.

That is a deliberate and valuable design. A frozen assimilation scheme is what makes the record comparable across decades. It is also precisely the information a backtest must not borrow. A value for a date decades before 2016 was never available to anyone on that date. It was produced later, by a system nobody had then, using observations that arrived afterwards.

Revised observations resemble corrected station data, and known-future inputs resemble the calendar or scheduled events available in advance. One difference matters. No forecaster changes the weather, and commercial systems can change the world they forecast. Promotions, staffing, and recommendations may influence future demand, so features must distinguish plans from outcomes affected by those plans.

A realistic backtest reconstructs the information publication process, not only the final historical values.

Version revised history and preliminary truth

Many time series are revised after they are first published, and the revision is not a rounding detail. On 9 September 2025 the U.S. Bureau of Labor Statistics announced a preliminary benchmark revision to March 2025 employment: “The preliminary estimate of the Current Employment Statistics (CES) national benchmark revision to total nonfarm employment for March 2025 is -911,000 (-0.6 percent)”. The final benchmark arrived with the release of January 2026 data, on 11 February 2026: “The March 2025 benchmarked, seasonally adjusted employment level for total nonfarm employment is 158,377,000”. That is a revision of 898,000 (-0.6 percent) against the previously published seasonally adjusted estimate, and of 862,000 (-0.5 percent) not seasonally adjusted, to 157,540,000. One month of employment, several published values, the last landing the better part of a year after the month itself.

Nor was this an aberration to be excluded as an outlier. A Federal Reserve Bank of Cleveland economic commentary by Pinheiro and Quinlan places the same revision at -0.54 percent of originally reported employment, “just marginally outside of the normal range” of roughly plus or minus 0.5 percent. A model trained on the final series and evaluated on the final series never meets the -911,000 version. That is the version every decision taken in the intervening months actually used.

Store publication or system time alongside valid time, so the pipeline can reconstruct vintage data. Evaluate both preliminary and final targets when they support different operational questions. Two public archives already do exactly this. The St. Louis Fed's ALFRED has been running since 2006: “ALFRED® allows you to retrieve each economic data release (vintage) that was available on a specific date in history.” The Federal Reserve Bank of Philadelphia's Real-Time Data Set for Macroeconomists is the same idea for macroeconomic aggregates, introduced by Croushore and Stark in 1999: “The data set consists of vintages, or snapshots, of the major macroeconomic data available at quarterly intervals in real time.”

A model may need to predict the first published value, the eventual final value, or both. The preliminary -911,000 and the final 898,000 are not one target measured twice. They are two targets, with different delays and different noise. Document whether training uses vintage snapshots, latest revised history, or simulated publication lags. Without that choice, backtest results are difficult to interpret.

The database standard has carried both clocks since December 2011. Kulkarni and Michels, writing in ACM SIGMOD Record, record how SQL:2011 separates them: “transaction time support is provided by system-versioned tables, which in turn contain the system-time period, and valid time support is provided by tables containing an application-time period”. The standard names the system-time period SYSTEM_TIME, and “users are allowed to define at most one application-time period and at most one system-time period per table”. The bookkeeping is not left to the application: “the system, rather than the user, maintains the start and end times of the periods of the rows”, and the design requires that “users be unable to modify the content of historical rows”.

Revision-aware data distinguishes what was believed then from what is known now.

Key takeaways