Time series analysis using Prophet in Python — Part 1: Math explained
Check out the video version here:
Summary
This text discusses the use of Prophet, a time series analysis tool in Python, and explains the mathematical concepts behind it, including trend models, seasonality models, and holiday models.
Abstract
The article begins with a brief introduction to the use of Prophet, a time series analysis tool in Python, and explains its mathematical foundations. The first part of the explanation focuses on the trend models, specifically the logistic trend model, and how carrying capacity and growth rate can change over time. The second part covers seasonality models, which are based on the Fourier series, and discusses the parameters involved in this model. The final part of the explanation details the holiday model, which models the linear effect of holidays on the time series data. The article concludes by summarizing the final model and listing the parameters that can be tuned in Prophet for time series analysis.
Opinions
Check out the video version here:
Prophet models time series as a generalized additive model (GAM) combining the trend function, seasonality function, holiday effects, and an error term in one model:

The logistic trend model is based on the logistic growth model:
𝑔(𝑡)=𝐶/(1+exp(−𝑘(𝑡−𝑚))
C: carrying capacity
k: growth rate
m: offset parameter
Here is an example plotting g(t) with m=0 and t from 0 to 49. As we can see here, carrying capacity and growth rate may change and the resulting logistic growth model will look very differently.

syntax for the plot:
To indicate that the carrying capacity is a function of time. We can write C as C(t).
With 𝛿𝑗 change in growth rate at time 𝑠𝑗, growth rate becomes:

Here is another way to write this equation. We can vectorize the change 𝛅 and create a vector 𝐚(𝑡) to indicate when change happens.

Growth rate at time t becomes:

With those two changes, the logistic trend model can be written as:

And similarly, the linear trend model can be written as:

Note that 𝛾 here is to adjust the offset parameter to connect the endpoints of segments.
Seasonality is modeled based on the Fourier series:

Which can be rewritten as 𝑋(𝑡)𝛽 with X(t) and 𝛽 specified as vectors:

Here is an example of the series and how the function changes regarding to a, b, N, and p (assuming a = a1 =… =aN and b = b1 =…= bN for simplicity).

Syntax for this plot:
Holiday model models the linear effect of the holidays, which is a vector of dummies (1 indicates holiday and 0 otherwise):
𝑍(𝑡)=[1(𝑡∈𝐷1),…,1(𝑡∈𝐷𝐿)]
ℎ(𝑡)=𝑍(𝑡)𝜅
Prior 𝜅∼𝑁(0,𝜈^2)∼ default 𝑁(0,0.5)
Combining all three models together, we get the final model for our time series analysis:
𝑦|𝑚,𝛿,𝛽,𝜅,𝜖,∼𝑁(𝑔(𝑡)+𝑠(𝑡)+ℎ(𝑡),𝜖)
Then based on the priors of the parameters and the data, we can find maximum a posterior (MAP) estimates for all parameters.
2. changepoint prior scale
3. changepoint range:
4. seasonality prior scale
5. holidays_prior_scale
6. seasonality_mode
7. yearly_seasonality
8. weekly_seasonality
changepoints = [dates]2. Specify seasonalities
add_seasonality3. Additional regressors
add_regressor4. Uncertainty
Next, I am going to show you how to use Prophet and how to tune your model in practice. Check it out!
Ref:
https://peerj.com/preprints/3190.pdf
https://facebook.github.io/prophet/docs/quick_start.html
Md Monsur aliUnlock Advanced Search Relevance: Bridging the Query-Document Gap with Innovative HyDE Techniques
Chris Kuo/Dr. DatamanWe often hear “the only thing that is certain is that nothing is certain.” We do not like uncertainty. We do not want to hear “tomorrow’s…