Lazy loaded image
Mathematics
Lazy loaded imageProphet Model
Words 1681Read Time 5 min
May 1, 2020
May 1, 2025
type
status
date
slug
summary
tags
category
icon
password

Prophet Model

The Prophet model can be expressed with the following formula:
Where:
  • y(t): The observed value (e.g., sales) at time t
  • g(t): The trend component, representing long-term changes (growth or decay)
  • s(t): The seasonal component, representing periodic fluctuations (e.g., weekly or yearly seasonality)
  • h(t): The holiday effect, representing the influence of specific holidays or events
  • : Noise (error), typically assumed to be random

1. Trend Component g(t)

The trend component captures the long-term direction of the data, which can be either linear or non-linear.

For Linear Trend:

The formula is:
Where:
  • : The intercept (starting value of the trend)
  • : The slope (rate of change)

For Non-Linear Trend (Logistic Growth):

If the data exhibits saturation or leveling off over time (e.g., sales reach a maximum capacity), Prophet uses a logistic growth model:
Where:
  • C: The maximum capacity (upper bound)
  • k: The growth rate
  • : The time when growth starts to slow down

2. Seasonality Component s(t)

Seasonality represents the periodic fluctuations in the data, such as daily, weekly, or yearly patterns.
Prophet supports three types of seasonality:
  • Daily seasonality: Variations within a single day (e.g., higher sales during the day and lower at night)
  • Weekly seasonality: Patterns that repeat every week (e.g., higher sales on weekends)
  • Yearly seasonality: Yearly patterns (e.g., holiday season spikes)
The seasonality component is modeled using Fourier Series. The Fourier Series decomposes periodic functions (like weekly or yearly cycles) into a sum of sine and cosine functions. The general formula is:
Where:
  • P: The period (e.g., 365 for yearly seasonality, 7 for weekly seasonality)
  • and : The coefficients that are learned during model fitting
  • N: The number of terms in the Fourier Series

3. Holiday Effects h(t)

Holiday effects capture the influence of specific events or holidays (e.g., Christmas, New Year’s) on the time series.
Holiday effects are modeled using indicator functions that take the value 1 on the holiday and 0 otherwise. For each holiday hih_ihi, its contribution is controlled by a coefficient γi\gamma_iγi:
Where:
  • is an indicator function that equals 1 if the date ttt is a holiday hih_ihi, otherwise 0.
  • is the effect of holiday hih_ihi on the target variable (e.g., sales), typically estimated during model fitting.

4. Noise

The noise term represents random variations in the data that cannot be explained by the trend, seasonality, or holidays. Prophet assumes this noise to be independent and identically distributed (iid), and it estimates the variance of the error term.

5. Adding the Components Together

Finally, Prophet combines the components (trend, seasonality, and holiday effects) to generate the final forecast. The formula is:

6. Model Fitting and Forecasting

Prophet uses Bayesian inference to fit the model and estimate the parameters. The fitting process involves maximizing the posterior probability to estimate the most likely values for the trend, seasonality, and holiday effects. This is done through a MCMC (Markov Chain Monte Carlo) or optimization algorithm.
  • Trend: Fitted using regression to estimate g(t).
  • Seasonality: Fitted using Fourier Series to capture s(t)s(t)s(t).
  • Holiday Effects: Estimated by modeling the influence of holidays on h(t).

7. Prediction

Once the model is fitted, Prophet can make predictions for future time points. The model will compute the forecast for each time point and provide the predicted value along with a confidence interval (upper and lower bounds).

8.Prophet's prediction process

how each component (trend, seasonality, and holiday effect) is computed and combined to make a final prediction? We will use a simple example with sales data and go step-by-step.

Sample Data:

Let's assume we have the following sales data:
Date
Sales
2024-01-01
200
2024-01-02
220
2024-01-03
210
2024-01-04
250
2024-01-05
240
We will use this data to simulate how Prophet calculates the trend, seasonality, and holiday effects, and combine them to make predictions.

1. Trend Calculation (g(t))

First, we calculate the trend. Prophet assumes that the data has a long-term trend, which could be either linear or nonlinear. For simplicity, we’ll assume a linear trend.
The formula for a linear trend is:
Where:
  • is the intercept (starting value of the trend),
  • is the slope (rate of change of the trend over time).

Calculation Steps:

  1. We fit a linear regression model to the data to estimate and . We convert the dates into a numerical form (e.g., t=0 for 2024-01-01, t=1 for 2024-01-02, etc.) and then use linear regression to estimate the parameters.
Here’s the regression equation:
In practice, you would use a tool like Python’s sklearn.linear_model.LinearRegression to fit this model.
Let’s assume we fit the model and get the following parameters:
  • = 210
  • = 8
Thus, the trend formula becomes:
g(t)=210+8⋅t
Now we can compute the trend values for each day:
Date
t (days since 2024-01-01)
g(t) (Trend)
2024-01-01
0
210
2024-01-02
1
218
2024-01-03
2
226
2024-01-04
3
234
2024-01-05
4
242

2. Seasonality Calculation (s(t))

Next, we calculate the seasonality. Seasonality reflects periodic fluctuations in the data, like weekly or yearly patterns. Prophet models this using Fourier Series.
The general formula for seasonality is:
Where:
  • P is the period (e.g., 1 for daily seasonality),
  • and are the Fourier coefficients that are estimated from the data.
For simplicity, let's assume we are modeling daily seasonality with only one frequency term (N=1) and the following Fourier coefficients:
  • = 10
  • = -5
Now, for each t, we calculate the seasonality component:
Here’s the computed seasonality for each day:
Date
t (days since 2024-01-01)
s(t)(Seasonality)
2024-01-01
0
10
2024-01-02
1
-5
2024-01-03
2
0
2024-01-04
3
5
2024-01-05
4
10

3. Holiday Effect Calculation (h(t))

If there are holiday effects, Prophet will include them in the model as well. A holiday effect is typically modeled using an indicator function, which is 1 on the holiday and 0 otherwise. Let's assume that 2024-01-04 is a holiday, and it has a positive effect on sales.
Let’s assume the holiday effect on 2024-01-04 is h(t)=20.
Here’s the holiday effect for each day:
Date
h(t) (Holiday Effect)
2024-01-01
0
2024-01-02
0
2024-01-03
0
2024-01-04
20
2024-01-05
0

4. Final Prediction (y(t)

Now, we combine the components (trend, seasonality, and holiday effect) to get the final prediction.
The formula for the final prediction is:
y(t) = g(t) + s(t) + h(t)
We simply add the trend, seasonality, and holiday effects for each day.
Here’s how we compute the predictions:
Date
Sales (Actual)
g(t) (Trend)
s(t)(Seasonality)
h(t)(Holiday Effect)
y(t)(Prediction)
2024-01-01
200
210
10
0
220
2024-01-02
220
218
-5
0
213
2024-01-03
210
226
0
0
226
2024-01-04
250
234
5
20
259
2024-01-05
240
242
10
0
252

Summary:

  • Trend: We modeled the long-term trend using linear regression.
  • Seasonality: We captured daily periodic fluctuations using Fourier series.
  • Holiday Effect: We added a holiday effect on 2024-01-04.
  • Final Prediction: We combined these components to get the final predicted values.
These steps illustrate how Prophet decomposes a time series into trend, seasonality, and holiday components, and combines them to make forecasts. In real-world scenarios, Prophet will automatically fit these components to the data, but the general process remains the same.

9.Holiday Effects in the Prophet Model

1. Components of the Prophet Model

The Prophet model is composed of the following key components:
  • Trend: Represents the long-term direction of the data (e.g., whether sales are increasing or decreasing).
  • Seasonality: Captures periodic changes in the data (e.g., weekly, monthly, or yearly patterns).
  • Holiday Effects: Models the impact of specific events or holidays on the data (e.g., Christmas, New Year’s).

2. Holiday Effects as an Additive Component

In Prophet, holiday effects are modeled as an additive component, meaning they are added to the baseline forecast, which already includes trend and seasonality.
For example:
  • If sales usually increase by 20 units during Christmas, Prophet will add 20 to the forecast for that date.
  • If a holiday usually results in lower sales, Prophet will subtract a value accordingly.

3. How Prophet Learns Holiday Effects

Prophet learns the holiday effects from historical data using the following process:

Step 1: Input Data

To allow Prophet to learn holiday effects, you must provide:
  • A list of dates representing holidays (e.g., Christmas, New Year’s).
  • Historical time series data for the target variable (e.g., daily sales), ideally covering multiple years and including the holidays.

Step 2: Modeling Holiday Effects

Prophet analyzes the impact of each holiday by:
  • Segmenting the data over time.
  • Comparing values on holidays with values on non-holiday dates.
The observed difference is interpreted as the holiday effect.

Step 3: Estimating the Size of the Holiday Effect

Prophet uses Maximum Likelihood Estimation (MLE) to estimate the effect size.
Example:
Date
Sales
Holiday
2021-12-25
300
Christmas
2022-12-25
320
Christmas
2022-12-24
250
(Non-holiday)
From this, Prophet may estimate that the Christmas effect is an increase of 20–30 units. This learned effect will be used for future forecasts.

Step 4: Applying Holiday Effects to Future Forecasts

Once learned, Prophet will apply these effects to future predictions:
  • If a future date (e.g., 2024-12-25) is a holiday, Prophet will adjust the forecast accordingly using the learned effect.
  • On non-holiday dates, the holiday effect is zero (no impact).

4. Additive Formula for Holiday Effects

In the Prophet model, the forecast is given by:
Where:
  • g(t): Trend component (long-term direction)
  • s(t): Seasonality component (periodic patterns)
  • h(t): Holiday effect (only non-zero on holidays)
  • : Random error (unexplained noise)
The holiday effect h(t)is applied only on specific holiday dates. On all other dates, h(t)=0.

5. Combining Seasonality and Holiday Effects

Sometimes holidays coincide with seasonal peaks. For instance, Christmas may fall during a winter seasonality peak.
Example:
  • Holiday effect (Christmas): +50 units
  • Seasonality effect (Winter): +30 units
The forecast will combine both, resulting in an increase of 80 units for that date.

6. Multiple Holidays and Separate Effects

If multiple holidays are provided, Prophet models each one individually, estimating a unique effect for each:
  • Christmas: +50 units
  • New Year’s Day: +20 units
These learned effects will be applied separately during future forecasts.

7. Continuous Learning Over Time

As more data becomes available, Prophet can update its understanding of holiday effects:
  • If the sales impact of a holiday increases or decreases over the years, Prophet will adjust the learned effect accordingly.
  • Retraining the model with updated data ensures that predictions stay relevant and accurate.

Example: Learned Holiday Effects

Date
Sales
Holiday
Learned Holiday Effect
2023-12-25
300
Christmas
+50
2024-12-25
320
Christmas
+55
2024-01-01
250
New Year’s
+30
Based on this:
  • Prophet learns that Christmas results in +50 to +55 units increase in sales.
  • New Year’s adds about +30 units.
  • These effects will be applied to future predictions, such as in 2025.

Summary

  • Holiday effects are learned from historical data, not predefined.
  • Prophet estimates the effect by comparing holiday vs. non-holiday behavior.
  • The effects are automatically applied in future forecasts.
  • Holiday effects are modeled as additive terms in the forecast equation.
上一篇
Cosine Similarity
下一篇
Statistical Test Decision Tree