Welcome to BxD Primer Series where we are covering topics such as Machine learning models, Neural Nets, GPT, Ensemble models, Hyper-automation in ‘one-post-one-topic’ format. Today’s post is on?Prophet Time Series Models. Let’s get started:
The What:
Prophet model is developed by Facebook. It is based on an additive regression model, which combines the following components to predict future values of a time series:
- Trend?is the underlying growth or decline in the data over time. Prophet fits a piecewise linear or logistic regression model to the data to capture changes in the trend over time.
- Seasonality?is the repeating patterns in data, such as daily, weekly, monthly or yearly cycles. Prophet incorporates seasonality into the model using Fourier series, which can capture both linear and nonlinear patterns.
- Holidays?or other significant events have impact on data. Prophet allows users to specify a list of holidays that are relevant to their data, and the model incorporates these effects into forecast.
- Error?is the variability or noise in data that cannot be explained by the trend, seasonality, or holiday effects. Prophet models this error using a normally distributed noise term.
Prophet has a number of other features that make it easy to use and customize:
- It can automatically detect and remove outliers in the data, which can improve the accuracy of the forecast.
- It can handle missing values in the data and interpolate them using a linear or spline method.
- It provides uncertainty estimates for the forecast, including both the point forecast and the range of possible outcomes.
Prophet is suitable for a wide range of applications, including forecasting, anomaly detection, and change-point detection.
The How:
Prophet is a decomposable additive model. The model assumes that observed time series can be decomposed into three main components: trend, seasonality, and holidays.
General equation of Prophet model can be written as:
??Trend Component,?g(t), captures the long-term behavior of data. Prophet uses a piecewise linear or logistic model to capture the trend.
- g(t) is the trend component of the time series at time t
- C is the carrying capacity or maximum possible value that the time series can reach
- k is the growth rate parameter
- t_0 is the inflection point or the time at which the growth rate starts to slow down
- k_1 and k_2 are the slopes of trend before and after change-point t_0, respectively
- m_1 and m_2 are the intercepts of trend before and after the change-point, respectively
Note: Prophet allows for multiple change-points in trend. Locations of change-points are determined using a Bayesian change-point detection algorithm that balances goodness of fit and complexity of model.
??Seasonality Component,?s(t), captures the periodic behavior of time series, such as daily, weekly, or monthly patterns. Prophet uses a Fourier series to model seasonality:
- s(t) is the seasonality component of the time series at time t
- N is the number of Fourier terms used to model seasonality
- a_n and b_n are the coefficients of the k’th Fourier term
- P is the period of seasonality (e.g., 365.25 for yearly seasonality)
??Holiday Component?takes a list of holidays and learns their effect in time series as:
- h(t) is the holiday component of the time series at time t
- m is the number of holidays
- k_j is the effect of the j’th holiday
- I(t = t_j) is a binary indicator function that takes value of 1 if t is the date of the j’th holiday, and 0 otherwise.
??Error Component?represents the deviation of actual value of time series at time t from predicted value based on the trend, seasonality, and holiday components. It is assumed to be normally distributed with mean 0.
? Parameters of model are estimated using a Bayesian approach. Model is fitted to the observed time series using maximum likelihood estimation. Process explained in our previous edition, check here.
? Models learns its parameters from historical training data and trained model equation can be used to make forecast on a future time window. Accuracy of the forecasts produced by Prophet will depend on the length of forecast window and length of historical data on which model is trained.
Tradeoffs in Selecting Forecast Window:
Once the model has been fitted to historical data, you can use it to make predictions for any forecast window that you specify. Consider below tradeoffs in selecting forecast window:
- Accuracy vs. Precision: Accuracy refers to how close the forecasted values are to actual values, while precision refers to the range of possible values for forecast. Generally, longer the forecast window, less accurate the forecast is likely to be, but the more precise it will be in terms of providing a range of possible outcomes.
- Data availability: Longer forecast windows require more historical data to be available for accurate predictions. If limited data is available or if data is very noisy, it may be better to use a shorter forecast window to reduce the risk of making inaccurate predictions.
- Time horizon of decision-making: For short-term operational decisions, a forecast window of a few days or weeks may be sufficient. For making longer-term strategic decisions, a forecast window of several months or years may be more appropriate.
- Forecast frequency: For making daily forecasts, a forecast window of one week may be appropriate, while a forecast window of one year may be more appropriate for annual forecasts.
Analyst-in-the-Loop Approach:
Analysts making forecasts often have extensive domain knowledge but limited statistical knowledge. In Prophet model, there are several places where analysts can alter the model to apply their expertise without requiring any understanding of underlying statistics.
- Capacities: Analysts may have external data for the total market size and can apply that knowledge directly by specifying capacities.
- Change-points: Known dates of change-points, such as dates of product changes, can be directly specified.
- Holidays and seasonality: Analysts have experience with which holidays impact growth in which regions, and they can directly input the relevant holiday dates and the applicable time scales, region of seasonality.
- Smoothing parameters: Analyst can select from a range of more global or locally smooth models. The seasonality and holiday smoothing parameters allow the analyst to tell the model how much of the historical seasonal variation is expected in the future.
The Why:
Reasons to use Prophet model:
- Particularly useful for time series data that exhibit strong seasonal patterns, as it is able to model any frequency of seasonality.
- Prophet has built-in imputation functionality to handle missing values, which can be useful for datasets with missing or incomplete data.
- Prophet is designed to be easy to use, with a simple API and intuitive parameters, making it accessible to users with limited experience in time series modeling.
- Allows for customization of many parameters, including seasonality, trend, and holiday effects, which can be adjusted to fit different types of time series data.
- Provides transparency into the model and results, including diagnostic plots and easily interpretable components, which can be helpful for understanding the modeling process and communicating results to stakeholders.
The Why Not:
Reasons to not use Prophet model:
- Prophet only supports univariate time series data, which may be a limitation for users with multivariate data or those seeking to incorporate external variables into model.
- While Prophet is designed to be easy to use, it still requires tuning of hyper-parameters, which can be time-consuming and require domain expertise to select appropriate values.
- If dataset is very small, Prophet may not be able to learn the underlying patterns and may produce inaccurate forecasts.
- Its underlying assumptions are simplistic and weak. It is not useful in cases where recent data has more value in prediction than older data.
Time for you to support:
- Reply to this email with your question
- Forward/Share to a friend who can benefit from this
- Chat on Substack with BxD (here)
- Engage with BxD on LinkedIN (here)
In next coming posts, we will cover one more time series model: Hidden Markov Models
Post that, we will start with Ensemble Models such as Stacking, Bagging, Boosting, Ensemble of Experts, Bayesian Model Averaging
Let us know your feedback!