Data & drivers
Feature engineering for time series
Most of the work is turning a clock and a few raw series into lags, rolling stats, and calendar flags the model can chew. Do that on a schedule, with no future leaking into the past, or the backtest is theater.
Updated Aug 9, 2026·9 min read
Raw series vs features
The target is a clock and a number. Features are what you build so a model can chew: lags, rolling stats, calendar flags, known-ahead covariates. Foundation models may ingest a raw window instead of thirty handmade columns. You still need a serving path that sees the same history training saw.
The first five features that usually matter
lag 1
yesterday
lag 7
last weekday
roll 28
recent level
holiday
calendar
promo
if known ahead
Lags
Lag 1 is yesterday. Lag 7 is last weekday. Lag 364 is “this weekday last year” if you have it and the calendar cooperates. Pick them from the decision, not from a list of integers in a blog. Too many lags on a short series overfit. Lag 0 of the target, when you are predicting now, is just the answer.
Rolling windows
A 7-day mean is a smoother yesterday. A 28-day standard deviation is a cheap volatility flag. Compute them on a shift: at Tuesday 6am, the window ends Monday. If the window includes today while predicting today, you leaked. Short windows chase noise. Long windows miss breaks. Many teams keep one of each.
The calendar
Holidays, payday, school terms, “is this a 4-day week.” These are the cheapest accurate features in the building. Do not make the model rediscover Christmas. And do not encode a holiday with a name the serving job cannot resolve in another country.
The leakage checklist
- Any statistic grouped by month that includes days after the origin.
- A rolling max that includes the label.
- Standardization fit on the full series including test.
- A covariate that arrives later than the forecast must ship.
Let models propose features. Do not let them invent a column that only exists in a notebook. The pipeline has to be boring and on a schedule, or 6am inference will not match the bake-off.
FAQ
- What features matter most in time series?
- Lagged values of the target, a seasonal lag (7, 12, 52), a short rolling mean, and a calendar. After that, covariates you will actually have at forecast time. Fancy embeddings do not rescue a leaked rolling max.
- What is leakage in feature engineering?
- Using information that would not have been known at the forecast moment — a rolling mean that includes today when you are predicting today, or a 'month total' computed from future days.
- Should I let a model invent features?
- Let it propose. You still need the pipeline to be deterministic at serving. A feature that exists only in a notebook will not be there at 6am when inference runs.
Keep going
Guide
Forecasting with covariates
A covariate is an extra series the model is allowed to see — a promo flag, a temperature, a price. Used well, it explains swings the target's past cannot. Used as a dump of every column you have, it just overfits last quarter.
Guide
Finding leading indicators
A leading indicator moves before the number you care about. Search queries before orders, bookings before departures, parts receipts before output. The lag is the product; correlation on the same day is just a mirror.
Guide
How to backtest a forecasting model
Backtesting asks the model to forecast a past window it was not trained on, then scores the miss. Walk the window forward so you see many 'futures,' not one lucky test month.
Use case
Production output forecasting
Forecast finished output from schedule, staffing, material availability, cycle time, downtime, and yield.
Use case
Energy load forecasting
Forecast demand by interval, feeder, zone, and customer class with weather-driven uncertainty.