How would you engineer lag, rolling-window and seasonal decomposition features for a time-series model?
Role: Data Scientist
Category: Statistics & Math
Difficulty: medium
Interview Round: Other
How would you engineer time-based features for a time-series prediction model, including lag features, rolling statistics, and seasonal decomposition?
```hint Check each feature's timestamps
For every feature, ask which timestamps it reads and compare that with the moment the forecast is actually made, including the forecast horizon.
```
```hint Two routes to seasonality
Seasonal structure can enter as past values at the seasonal period or as functions of the target date's calendar. Consider what each one gives a model.
```
### What a Strong Answer Covers
- How lag features are chosen (autocorrelation, seasonal periods, forecast horizon)
- Which rolling statistics to compute and how to align them so they exclude the target
- How calendar, Fourier and decomposition features encode seasonality, and how to compute decomposition features without leakage
- How to validate the model with time-ordered splits
- Practical pitfalls such as irregular timestamps, many series in one table, missing early rows and trend extrapolation
### Follow-up Questions
- How do the features change when you forecast 14 days ahead instead of 1 day?
- You have 5,000 stores in one table. What changes in how you compute lags and rolling windows?
- A gradient-boosted model badly underpredicts after a sustained growth trend. Why, and what would you change?
- How would you encode a holiday whose date moves every year, along with its effect on the days around it?
Overview: Asks how to build lag features, rolling-window statistics, calendar terms and seasonal decomposition features for a time-series prediction model. Tests forecasting feature design, awareness of leakage across the forecast horizon, and time-ordered validation.