Time series analysis using Prophet in Python — Math explained
Skills:
Research Methods80%Reading ML Papers80%Paper Reproduction70%RAG Evaluation60%Advanced RAG50%
Key Takeaways
The video explains time series analysis using Prophet in Python, covering the math behind the model, including trend, seasonality, and holiday effect components. It also demonstrates how to use Prophet to automatically detect change points, add custom seasonality, and include regressors.
Full Transcript
profit models time series as a generalized uh additive model combining the trend function uh Seas seasonality function the holiday effects and air term in the model uh I'm going to talk about each of those in details in the next few sections uh first of all the trend model can be modeled as a logistic TR model or linear Trend model um the logistic Trend model is based on logistic growth model uh the basic function where C is the carrying capacity um the K is the growth rate m is the offset parameter here in here is an example uh plotting the trend function with M = to zero and T from 0 0 to 29 uh which is 50 data points um as we can see here the carrying capacity and the growth rate may change over time uh and the resulting logistic growth model will look very differently um profit took into account those changes um by I first change the carrying capacity uh from C to CT um assume that the and the caring capacity is a function of time and secondly assumes that the growth rate can change over time as well um with with Delta J change in growth rate at time SJ the growth rate becomes K plus the sum of all rate changes up to that point uh another way to write this function is to vectorize the change Delta as a vector and create another Vector a t uh to indicate when the change happens then the growth rate at time T can be written as k + a transpose time Delta the um combining those two different changes uh our final logistic trim mod looks like this again CT is the carrying capacity at time t uh K is the growth rate a transpose Delta is the changing growth rate at time T um m is the offset parameter uh we have an extra parameter here gamma is calculated based on the other parameters to adjust the offset parameter to connect the end points of segments so that the function can be smooth uh similarly the linear Trend model um have a uh this is the slope basically the growth rate and the changeing the slope of this linear function uh a transpose Delta uh which is the changing growth rate or slope at time t m is the offset parameter or intercept of the model uh again gamma is tojust adjust adjust off that parameter to connect the segments so in some R what parameters are in the trend model again here are the equations for the ltis trend model and the linear Trend model um in profit CT is user defined um the the uh the offset parameter M given a normal distribution of mean zero and variance five this is the default in the model uh SJ is uh when the CH when the change happens uh this is automatically selected based on your data uh so we don't need to worry about it uh Delta J is how much the change happens at time SJ it follows the LA plus um distribution of um the location parameter is zero and the scale parameter is to uh to regulates the trend flexib higher t means higher Trend flexibil Flex flexibility and finally gamma's calculated based on the other parameters um we don't need to worry about that one neither uh the second component of the time series model is the seasonality St it is model based on the four real series which is a combination of weighted cosiness and SS uh can be written as XT beta XT is a vector of cosine and SS beta is a vector of Weights uh the N here represents the order of four RAR series basically how many cosine and signs do you want in your model um P here represents period it can be um a year a month a week or anything that you might Define as a period uh here is the example of the time series uh the foure series and how the fourar series may change um regarding to a b n and p here we're assumed that um all the weights for a are the same B are the same for Simplicity but in reality all the weights are can be very different uh so what are the parameters in the seasonality model for yearly seasonality the default setting for uh the order of the fourar series is is 10 uh P the period equals to um 365.25 uh for weekly seasonality uh n = to 3 and P = to 7 um the the the vector of the weights beta follows uh normal distribution um mean zero and standard deviation Sigma where Sigma regulates the strength of of the seasonality uh the final component uh the third component of the model is the holiday effect HT um it models the linear effect of the holidays uh which is a vector of a dumy variable one indicating holiday and zero non holiday um K is just the U the effect of the holiday which follows uh normal distribution of mean zero and variance um .5 this is the default so combining all three models together we get a final model for our time series analysis um follow um normal distribution again um then based on the priers of the parameters in our data we have find the maximum posterior estimates for our parameters so that's basically how the math works okay so in profit um there are several parameters we can tune in the model um first of all in the trend model the default setting is to use a linear growth Trend um but we can't change it to logistic Trend if you think that fits your question better or your data better um also the chain Point prior scale on to can be changed um uh we have learned before that the the change rate Delta J at time SJ follows AAS distribution with the uh scale parameter T the default is 05 um but we can change this value to to higher values uh higher value means more sorry should be just one more more flexible Trend um and then thirdly we have the change Point range the default value is 08 in profit um which means the change points um can only apply to 80% of the data to better project forward and avoid overfitting at the end um but we can change this value to to .9 if you want to apply change points to more data or 7 if you want to apply it to less data um but point8 is a good default value um for seasonality function um first first of all we can tune the seasonality prior skill um we known that beta uh which is the vector of the weights um of the fourer for distrib forer series The the alphas and betas um the weights for the uh cosiness and signs follow a normal distribution uh the default of the sigma is 10 um in the SE seasonal mode the default is additive uh which means the model combines the uh the isal uh with the trend function add them up together um but we can also Define it as multiplicative if you think your cality function um grows with the trend um so instead of we use GT Plus St we can use GT * St here the year seasonality uh the default is false the data doesn't fit yearly seasonality um but if you set the yearly Cincinnati equals to true the default order of the for series is 10 as we said before um higher value corresponds to higher frequent changes uh we can change this value if you think uh we should fit more cosign and signs in your data and lastly weekly cality um the default in the model is true um the order of the for series is three um higher values corresponds to higher frequent changes uh again the P here is seven and P for the yearly since now is uh 365.25 those normally we don't change those we don't need to tun those parameters the only thing we need to T here is the is the n the order of the four series uh for holidays we can t the holidays prior scale um the default value is 10 lower values meaning lower holiday effects uh reducing the value can avoid overfitting so if you think you you have a strong holiday effects you can increase the value uh but if you think the holiday effect the holiday effects it maybe overfitting or should be smaller uh you can reduce the value uh there are several other is uh features in profit uh you should consider using your model first is the locations of the change points SJ um it is automatically detected as we said before um based on your data to to find uh def find the best SJ to uh to fure data it can be specified using change points equals a list of dates um so you can specify your own change points States if there is a product launch or anything important like that uh you want to specify your change points um you can also specify seasonalities the default um season it component in the data is the weekly seasonality uh we can add the yearly seasonality by setting yearly seasonality equal to True um if you want to add any other types of seasonalities for example monthly seasonality or quarterly seasonality you can use add seasonality function uh another great thing about profit is that add additional regressors we can add uh those regressors simply using add regressor function this is like the great the the greatest featuring profit ever because all the other time series models uh cannot easily add regressors and give us um effects of those regressors profit makes it really easy to add different regressors uh and see those effects and finally um when we model this time series and predict the future uh we get the confidence interval uh which is the uncertainty in our data in the trend model we assume there there are similar Trends in the future similar Trend changes in the future um therefore higher chain point prior skill lead to higher uncertainty and but for seasonality uh we don't have this kind of seasonality of this uncertainty embedded in the model therefore we need to use mcmc sing sampling to C the UNC inity
Original Description
Check out my article here: https://medium.com/analytics-vidhya/time-series-analysis-using-prophet-in-python-part-1-math-explained-5936509c175c
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from Sophia Yang · Sophia Yang · 2 of 60
1
▶
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
Customer lifetime value in a discrete-time contractual setting (math and Python implementation)
Sophia Yang
Time series analysis using Prophet in Python — Math explained
Sophia Yang
Multiclass logistic/softmax regression from scratch
Sophia Yang
Deploy a Python Visualization Panel App to Google Cloud App Engine
Sophia Yang
Deploy a Python Visualization Panel App to Google Cloud Run
Sophia Yang
[Read a paper (with code)] Beyond Accuracy: Behavioral Testing of NLP models with CheckList
Sophia Yang
5-step data science workflow
Sophia Yang
Multi-armed bandit algorithms - ETC Explore then Commit
Sophia Yang
Multi-armed bandit algorithms - Epsilon greedy algorithm
Sophia Yang
User retention analysis framework | data science product sense
Sophia Yang
Visualization and Interactive Dashboard in Python: My favorite Python Viz tools — HoloViz
Sophia Yang
Multi-armed bandit algorithms: Thompson Sampling
Sophia Yang
The Easiest Way to Create an Interactive Dashboard in Python
Sophia Yang
Big Data Visualization Using Datashader in Python | How does Datashader work and why is it so fast?
Sophia Yang
Why do you want to be a data scientist? Don't be a data scientist if ...
Sophia Yang
Johnny Depp v Amber Heard Twitter Sentiment Analysis | Is Camille Vasquez the real winner | 🤗 NLP
Sophia Yang
How to build a product that sells itself | Product-led Growth | Book Summary | Read a book with me
Sophia Yang
Designing Machine Learning Systems | book summary | Read a book with me
Sophia Yang
Where do data scientists/analysts go next? Love and hate in data analytics (ft. Shashank Kalanithi)
Sophia Yang
Meet the Author: Fundamentals of Data Engineering | DS/ML book club
Sophia Yang
What's new in hvPlot releases 0.8.0 & 0.8.1?
Sophia Yang
Meet the Author: Machine Learning Design Patterns | What do ML/Research Engineers do at Google?
Sophia Yang
Machine Learning Design Patterns | Google Executive | Investor | Meet the Author
Sophia Yang
How to solve data quality issues | Data Reliability | Meet the Author
Sophia Yang
Reliable Machine Learning author interview | DS/ML book club
Sophia Yang
Toronto VLOG | First vlog | Meet my favorite author | Toronto ML Summit conference
Sophia Yang
TOP 6 tech news in 2022 #shorts
Sophia Yang
How to deploy a Panel app to Hugging Face using Docker?
Sophia Yang
Tech news this week | ChatGPT, Hacks, Snowflake, CES #shorts
Sophia Yang
🗞️ Tech news this week: ChatGPT, DreamerV3, Muse, VALL-E, Mineral, DoNotPay, Tesla, SBF... #shorts
Sophia Yang
Tech news this week | Boston Dynamics, Microsoft, Snowflake, Google, and more #shorts
Sophia Yang
The story of Metaflow | Effective Data Science Infrastructure | Book author interview
Sophia Yang
Tech news this week #shorts
Sophia Yang
A day in life of a data scientist | Data Day Texas | Interview 12 authors/speakers
Sophia Yang
Tech news this week #shorts
Sophia Yang
Explainable AI with Shapley Values (Part 1: Game Theory)
Sophia Yang
Explainable AI with Shapley Values (Part 2: Estimate Shapley Values)
Sophia Yang
Explainable AI with Shapley Values (Part 3: KernelSHAP)
Sophia Yang
Tech news this week | AI search war between Microsoft and Google #shorts
Sophia Yang
The Story of ChatGPT's creator OpenAI | From Riches to Fame
Sophia Yang
Explainable AI for Practitioners | Must-read for XAI | author interview
Sophia Yang
Train your own language model with nanoGPT | Let’s build a songwriter
Sophia Yang
The easiest way to work with large language models | Learn LangChain in 10min
Sophia Yang
The BEST browser? AI article summary, image generation, website insights. Microsoft Edge Copilot!
Sophia Yang
startup scene in data | insights from 50+ data startups from Data Council
Sophia Yang
NLP with Transformers author interview with Lewis Tunstall from Hugging Face
Sophia Yang
4 ways to do question answering in LangChain | chat with long PDF docs | BEST method
Sophia Yang
5 Steps to Build a Question Answering PDF Chatbot: LangChain + OpenAI + Panel + HuggingFace.
Sophia Yang
4 Autonomous AI Agents: “Westworld” simulation, Camel, BabyAGI, AutoGPT, Camel ⭐ LangChain ⭐
Sophia Yang
MiniGPT4: image understanding & open-source!
Sophia Yang
BEST Practices in Prompt Engineering: Learnings and Thoughts from Andrew Ng's New Course
Sophia Yang
Designing Machine Learning Systems author interview with Chip Huyen
Sophia Yang
Tech news this week: code interpreter, Mojo, Redpajama, MPT7b, StarCoder #shorts
Sophia Yang
🤗 Hugging Face Transformers Agent | LangChain comparisons
Sophia Yang
📢 Tech news this week #shorts
Sophia Yang
📢 Tech news this week #shorts
Sophia Yang
The BEST ChatGPT Plugins | Brand NEW Bing Search | Web browsing, CODING, summarizing, and more
Sophia Yang
Tech news this week #shorts #short
Sophia Yang
📢 Tech news this week #shorts
Sophia Yang
Deep Learning with PyTorch Author Interview with Eli Stevens, Luca Antiga, and Thomas Viehmann
Sophia Yang
More on: Research Methods
View skill →Related AI Lessons
⚡
⚡
⚡
⚡
I Spent Weeks Looking for a Research Gap Before I Realized I Was Searching the Wrong Way
Medium · AI
ICMI 2026 Reviews [D]
Reddit r/MachineLearning
Workshop submission for main conference paper under review [D]
Reddit r/MachineLearning
Kept context-switching between arxiv, OpenReview, GitHub, and HuggingFace for every paper, so I built this. Chrome extension + website with everything inline, plus citation graph + SPECTER2 neighbors. 3M papers, free, feedback welcome [P]
Reddit r/MachineLearning
🎓
Tutor Explanation
DeepCamp AI