Time-Series Feature Engineering
What you'll learn: How to create temporal features, rolling windows, and lag features in production without introducing data leakage.
The Core Challenge
Time-series data adds a critical dimension to ML: time itself. Unlike static datasets, every data point has a temporal ordering that you must respect. In production, you need features like "average sales over the past 7 days" or "value from 3 hours ago"—but computing these incorrectly can cause data leakage, where future information sneaks into training examples, making your model appear artificially accurate during development but fail catastrophically in production.
Key Techniques
Lag Features
Create shifted versions of your data: value_lag_1 is yesterday's value, value_lag_7 is last week's. These capture recent history without peeking forward.
Rolling Windows
Compute statistics over sliding time windows: rolling mean, standard deviation, min/max over the past N timesteps. Think of it like a moving spotlight scanning your data backwards only.
Temporal Features
Extract calendar-based patterns: hour of day, day of week, month, is_weekend, is_holiday. These capture cyclical patterns humans create.
The Golden Rule: Time Cutoffs
Never use future data to compute features for past predictions. Your feature pipeline must respect the same time boundary in both training and serving. If your model trains on data up to time T, features for time T can only use information from before T.
In production, this means your feature store must compute rolling statistics using only historical data available at prediction time—no backwards-looking aggregations that wouldn't exist in real deployment.
Key Takeaway: Time-series feature engineering requires strict temporal discipline—always compute features using only past data relative to each prediction timestamp, maintaining identical logic between training pipelines and real-time serving to prevent leakage.