ML Systems Lab Open interactive version →
Intermediate 40 min read seasonalitySTLdecompositionFourierX-13

Seasonality & Decomposition

STL, additive vs multiplicative, X-13-ARIMA-SEATS, Fourier terms, irregular seasonality

A time series with both trend and seasonality is hard to model directly: the trend makes the series non-stationary, and the seasonal component repeats at a fixed period but with amplitude that may scale with the trend level. Modelling the combined series forces a single model to represent structure operating at two different timescales simultaneously. Decomposition separates these into three components — trend, seasonal, residual — so each can be modelled, forecast, and analysed independently. Choosing additive versus multiplicative decomposition is not aesthetic: it determines whether the seasonal component is a fixed absolute number or a fraction of the current level. Get it wrong and every downstream forecast inherits systematic bias. STL dominates classical decomposition for most ML work because it lets the seasonal component evolve and is robust to outliers. But STL's biggest limitation is also its most common production failure: it encodes seasonality at a fixed calendar period and cannot handle events that shift across the calendar, like Black Friday.

Key points

Takeaway

The practical insight that separates strong candidates is knowing when STL fails and what to do instead. STL handles smoothly evolving seasonality at a fixed calendar period but is blind to calendar-shifting events (Black Friday, Ramadan, Easter) because it assumes the seasonal spike falls at the same calendar week each year. The diagnostic — "seasonal component smeared across 3-4 weeks, peak attenuated" — identifies STL failure, and the fix is explicit holiday features or event indicators rather than encoding the event in the seasonal component.

Recap

Check your understanding

Q1. Weekly website traffic shows seasonal amplitude doubling over 3 years while trend also doubles. Which TWO statements about additive vs multiplicative decomposition are correct?

Q2. You are building a real-time anomaly detector for server error rates, which show strong daily and weekly patterns. STL fails because STL requires the series to be longer than two periods and the seasonal window must be odd. For 10-minute data with both daily (144 points/period) and weekly (1008 points/period) seasonality, what is your approach?

Q3. A stakeholder asks why your Black Friday sales forecast is consistently off by 20%. Your model uses STL decomposition with a fixed 52-week seasonal pattern. What is the root cause?

Q4. What does it mean to set s.window="periodic" in STL, when is it correct to do so, and what is the risk of always using it?

Try it interactively

ML Systems Lab is a free interview-prep platform for ML engineers — work through the full interactive module, quizzes, and drills.

Open ML Systems Lab →