Time Series & Forecasting

Spot the Seasons

Sales have three things mixed together: a slow climb, a pattern that repeats, and random noise. Find the repeat length and the robot will pull them apart.

Try to guess how many steps it takes before the pattern starts over. Slide Pattern length and watch the Season fit meter.

One line, three ingredients

Top: your sales and the slow trend. Middle: the repeating pattern the robot found. Bottom: what is left over (noise).

Challenges

Find the weekly beat: in Daily sales, get the Season fit to 70% or more.
Wrong guess: pick a length where the fit drops below 10%. A wrong ruler finds nothing.
Echo: pick double the real length. Why does it still fit well?
Switch to Monthly sales and find its yearly repeat of 12 months.

What just happened?

For grown-ups: what's really going on

This is a classical additive decomposition, the idea behind STL: yt = trendt + seasont mod p + remaindert.

  • Trend: a centered moving average of length p (a 2×p average when p is even). Ends of the series, where the window does not fit, are held flat.
  • Season: for each position in the cycle, average the detrended values, then subtract their mean so the season sums to zero.
  • Season fit is the strength of seasonality max(0, 1 − Var(remainder) / Var(detrended)). It peaks at the true period and at its multiples. This scan is a crude cousin of the autocorrelation function and the periodogram.
  • Real STL uses LOESS smoothing so the seasonal shape can change slowly over time. Multiplicative seasonality (swings that grow with the level) is handled by taking logs first.
  • Seasonal structure is the main reason naive forecasts fail, which the next lesson tackles.

Further reading: Cleveland et al. (1990), STL: A Seasonal-Trend Decomposition Procedure Based on Loess.