Prophet › Formula
Machine Learning from ScratchAll chapters Prophet › FormulaOne section · Sections in this chapter2 / 8 ↓
Reading tools Definitions & inline links
Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.
Article links
Make inline references clickable
To understand how Prophet works, we need to think about what makes a time series predictable. Most time series contain several distinct patterns that combine to create the values we observe. Prophet's mathematical foundation is built on the idea that we can break down any time series into separate, interpretable components and then add them together to reconstruct the original series. This decomposition approach makes forecasts both accurate and understandable.
Why Decomposition Matters
Imagine you're forecasting daily sales for an e-commerce store. The sales on any given day are influenced by multiple factors: the overall business growth (trend), recurring patterns like higher weekend sales (seasonality), special events like Black Friday (holidays), and random fluctuations (noise). If we can separate these components mathematically, we can understand what drives our forecasts and make better predictions.
Prophet's additive model does exactly this. It assumes that each component contributes independently to the final value, which means we can model and forecast each component separately, then combine them to get the full prediction. This approach is powerful because it matches how we naturally think about time series: as the sum of different effects rather than a single complex pattern.
The Additive Model
The fundamental equation that captures this decomposition is:
where:
-: the observed time series value at time
- : the trend component capturing long-term growth or decline
- : the seasonal component capturing recurring patterns
- : the holiday component capturing irregular events
- : the error term representing random noise
This equation tells us that at any point in time, the value we observe is simply the sum of these four components. The additive structure means each component contributes independently, making the model highly interpretable. If we want to understand why sales were high on a particular day, we can look at each component separately: was it due to overall growth, seasonal patterns, a holiday effect, or just random variation?

Trend Component:
The trend component captures the long-term direction of your time series. Think of it as the underlying growth or decline pattern that persists over time, separate from seasonal fluctuations or one-time events. Prophet models this trend in a flexible way that can adapt when the growth rate changes.
Why Changepoints Matter
Real-world time series rarely grow at a constant rate forever. A company might grow rapidly in its early years, then slow down as it matures. A product might see a sudden boost after a marketing campaign. Prophet handles these structural breaks through changepoints, which are points in time where the growth rate is allowed to change. This flexibility lets the model capture realistic business dynamics.
Linear Trend Model
For time series that grow or decline linearly, Prophet uses:
where:
- : the base growth rate (how fast the series grows per unit time)
- : a vector of rate changes at each changepoint
- : the base offset (the starting value)
- : a vector of offset adjustments at changepoints (ensures continuity)
- : a vector indicating which changepoints are active at time (1 if the changepoint has occurred, 0 otherwise)
The term adjusts the growth rate based on which changepoints have occurred by time . Similarly, adjusts the offset to ensure the trend function remains continuous even when the growth rate changes. This formulation allows the trend to smoothly adapt to structural breaks in the data.

Logistic Growth Trend Model
For time series that approach a maximum value (like market saturation), Prophet uses logistic growth:
where is the carrying capacity, representing the maximum value the series can reach. This model captures the S-shaped growth pattern common in business scenarios where growth slows as a market saturates.
The logistic function starts near zero, grows rapidly in the middle, then slows down as it approaches the carrying capacity. The changepoint mechanism works the same way as in the linear model, allowing the growth rate to change over time while maintaining continuity.
Seasonal Component:
Seasonal patterns are recurring fluctuations that repeat at regular intervals. Daily sales might be higher on weekends, monthly revenue might peak in December, or website traffic might spike every Monday morning. Prophet captures these patterns using Fourier series, which can represent any periodic function as a sum of sine and cosine waves.
Why Fourier Series?
Fourier series are powerful because they can approximate any periodic pattern, no matter how complex. Instead of assuming a specific shape for seasonality (like a simple sine wave), Prophet uses multiple Fourier terms to capture detailed patterns. This flexibility means Prophet can model everything from simple weekly patterns to complex multi-year cycles.
The seasonal component is defined as:
where:
-: the number of Fourier terms (more terms allow more complex patterns)
- : the period of the seasonality (365.25 for yearly, 7 for weekly, etc.)
- : Fourier coefficients learned from data (determine the shape of the pattern)
Each term in the sum represents a harmonic of the base frequency. The first term () captures the fundamental seasonal pattern, while higher-order terms () capture more complex variations. By learning the coefficients and from data, Prophet automatically discovers the seasonal pattern without requiring you to specify its exact form.

Multiple Seasonalities
Prophet can model multiple seasonal patterns simultaneously. For example, daily sales data might have both weekly patterns (higher on weekends) and yearly patterns (higher in December). Each seasonality gets its own Fourier series with an appropriate period, and they're all added together in the seasonal component.
Holiday Component:
Holidays and special events create irregular spikes or dips that don't follow regular seasonal patterns. Black Friday sales, Christmas shopping, or product launches create one-time effects that need special handling. Prophet's holiday component allows you to explicitly model these events.
The holiday component is:
where:
-: the effect size of holiday (learned from data)
- : an indicator function that equals 1 if time falls within the window for holiday , and 0 otherwise
This formulation is simple but effective. For each holiday you specify, Prophet learns how much it affects the time series (the parameter). The indicator function ensures the holiday effect only applies during the relevant time window. You can specify windows that extend before and after the holiday to capture effects like pre-Christmas shopping or post-holiday returns.
Mathematical Properties
Prophet's additive decomposition has several mathematical properties that make it powerful and reliable. Under certain conditions, there is typically one way to separate a given time series into its trend and seasonal components, including holiday effects. This uniqueness ensures that the model's interpretation is well-defined and consistent.
The model uses Bayesian inference to estimate all parameters. This provides several advantages. First, it naturally incorporates uncertainty into the parameter estimates, which propagates to forecast uncertainty intervals. Second, the Bayesian framework allows for informative priors that encode domain knowledge, such as expected holiday effect sizes or typical growth rates. Finally, Bayesian inference provides a principled way to handle the tradeoff between model flexibility and overfitting.
The Fourier series representation of seasonality is powerful because of a fundamental mathematical result: any periodic function can be approximated arbitrarily well by a Fourier series with enough terms. By adjusting the number of Fourier terms, Prophet can capture seasonal patterns ranging from simple sine waves to complex multi-periodic structures.
The changepoint detection mechanism uses a sparse prior, which assumes that most time points don't have trend changes, but allows for changes when the data strongly suggests them. This prior prevents the model from overfitting by creating changepoints everywhere, while still being flexible enough to capture structural breaks supported by the data. The balance between flexibility and parsimony is controlled by the changepoint_prior_scale parameter, which determines how easily the model will create new changepoints.