How Prophet fits trend, seasonality and holidays
Today let's understand Prophet, a forecasting model that splits a series into a trend, a repeating season and a set of holiday effects, fits each one separately, and adds them back together.
Here is the running example. Victoria, the Australian state, records its electricity grid demand every half hour. Add those readings up into a daily total and take 120 consecutive days, November 1, 2012 through February 28, 2013, real numbers from the tsibbledata package. Over those 120 days demand averaged 220.0 GWh a day, as low as 161.1 GWh on its quietest day and as high as 294.5 GWh on its busiest.
Here is the whole series, one point for each day.
Notice three things in that line. It drifts a little higher through the back half of the window than the front. It rises and falls on a roughly weekly rhythm. And a handful of days drop sharply below their neighbours, for no reason a calendar-free eye could name.
The three components Prophet adds together
Prophet writes demand on day \(t\) as one sum of three parts plus whatever is left over:
\[ y(t) = \text{trend}(t) + \text{seasonality}(t) + \text{holidays}(t) + \varepsilon(t) \]
trend(t) is the slow drift: whether demand is generally climbing or falling as the months pass. seasonality(t) is what an ordinary week looks like, the repeating rise and fall from Monday through Sunday. holidays(t) is which specific calendar dates break that ordinary pattern, a public holiday for instance. \(\varepsilon(t)\) is the error, everything on that day the other three do not explain.
These four pieces add together, they never multiply. So a big holiday effect on a low-trend day still just subtracts from whatever trend and season already put there, it does not scale them up or down.
Before fitting anything, ground trend and swing in the series' own numbers.
220 GWh a day is the level trend(t) drifts around. 28.6 GWh is roughly how far a typical day sits from that level, once you mix in every week's rise and fall together with every holiday's drop. trend(t), seasonality(t) and holidays(t) each pull one piece of that 28.6 GWh swing away from the rest, starting with trend(t).