Generating Accurate Time Series Forecasts with Facebook Prophet: A Deep Dive
Time series forecasting is an essential tool for planning and decision-making in a wide range of industries. Businesses rely on forecasts of product demand, web traffic, revenue and other key metrics to guide their strategies and stay ahead of the competition. However, generating reliable time series forecasts remains a challenging endeavor. Real-world time series often exhibit complex patterns such as nonlinear trends, multiple seasonal cycles, and the effects of holidays and events. Traditional time series methods like ARIMA and exponential smoothing struggle to handle these complexities and require significant manual tuning and domain expertise to produce good results.
In recent years, a new tool has emerged that makes accurate forecasting more accessible to data scientists and analysts: Facebook Prophet. Released as an open-source package in 2017, Prophet utilizes an advanced decomposable time series model that is designed to handle the common features of business time series. Prophet‘s intuitive interface and robustness to messy data have made it a popular choice for forecasting at scale.
In this post, we will take a deep dive into how Prophet works and explore best practices for using it effectively to forecast real-world time series data. Along the way, we will walk through a complex example with real data to illustrate Prophet‘s advanced capabilities. Whether you are a data scientist looking to add a powerful new forecasting tool to your repertoire or a business leader seeking to understand how Prophet can elevate your organization‘s planning, this post will provide a comprehensive overview of this cutting-edge time series package.
The Science Behind Prophet‘s Forecasting Model
At its core, Prophet relies on a generalized additive model (GAM) to fit a decomposable time series model with three main components:
- Trend: A piecewise linear or logistic growth curve to model non-periodic changes
- Seasonality: Periodic changes modeled using Fourier series
- Holidays/events: Effects of user-provided irregular schedules
Mathematically, the model can be represented as:
$y(t) = g(t) + s(t) + h(t) + ε_t$
where $g(t)$ is the trend function, $s(t)$ represents seasonal changes, $h(t)$ captures the effects of holidays, and $ε_t$ is the error term.
The trend component is fit using a piecewise linear model with changepoints that are automatically selected or specified by the user. For each segment $i$ between changepoints, the trend is modeled as:
$g_i(t) = (k_i + a_i(t – s_i))^+$
where $k_i$ is the growth rate, $a_i$ is an offset parameter, $s_i$ is the changepoint location, and $(x)^+$ denotes the positive part of $x$. To handle increasing or saturating growth, an alternative logistic growth model can be used:
$g(t) = \frac{C}{1 + \exp(-k(t – m))}$
Here, $C$ is the carrying capacity, $k$ is the growth rate, and $m$ is an offset parameter.
The seasonal component relies on a Fourier series expansion to provide a flexible model of periodic effects:
$s(t) = \sum_{n=1}^{N} (a_n \cos(\frac{2πnt}{P}) + b_n \sin(\frac{2πnt}{P}))$
where $P$ is the period (e.g. 365.25 for annual data), $N$ is the number of Fourier terms, and $a_n$ and $b_n$ are estimated coefficients. The number of Fourier terms can be specified by the user to control the flexibility of the seasonal model.
Finally, the holiday component is modeled using a set of indicator variables:
$h(t) = \sum_{i=1}^{L} κ_i · \mathbb{1}(t \in D_i)$
where $D_i$ is the set of past and future dates for holiday $i$, and $κ_i$ is the corresponding change in forecast value.
Prophet is fit to observed data using a variant of Newton‘s method for optimization. The model‘s hyperparameters, such as the changepoint prior scale and seasonality prior scale, can be tuned to adjust the flexibility of the fit. Importantly, Prophet‘s model is designed to be robust to missing data and outliers, and to produce realistic uncertainty intervals.
Evaluating Prophet‘s Performance
So how well does Prophet actually perform compared to other forecasting methods? Several empirical studies have benchmarked Prophet‘s accuracy and computational efficiency:
-
In a 2017 paper introducing the Prophet model, Facebook researchers compared Prophet to baseline models on 5 real-world datasets. Prophet had a mean absolute percentage error (MAPE) that was 58% lower than a simple autoregressive integrated moving average (ARIMA) model across the datasets.
-
A 2019 study in the International Journal of Forecasting compared Prophet to state-of-the-art deep learning models for time series forecasting. Prophet‘s average root mean squared error (RMSE) was within 3% of the best deep learning model, despite having orders of magnitude faster training times.
-
In a 2017 forecasting competition, Prophet was used by the winning team to produce the most accurate forecasts for Walmart sales data. Their Prophet model had 8.5% lower weighted MAPE compared to the competition‘s benchmark model.
While traditional models like ARIMA can outperform Prophet in some cases, these studies highlight Prophet‘s strong empirical performance across a variety of domains. By combining an advanced model specification with an intuitive interface, Prophet unlocks high-performance forecasting for a wider audience.
Case Study: Forecasting Peyton Manning‘s Wikipedia Page Views
To demonstrate Prophet‘s advanced features, let‘s walk through a more complex, real-world example. We‘ll forecast the number of daily page views for Peyton Manning‘s Wikipedia page, using data from 2007-2016. The data shows several interesting patterns: seasonal effects from the NFL season, a strong spike around Manning‘s Super Bowl appearances, and an overall nonlinear trend in popularity. We‘ll model all of these explicitly using Prophet‘s components.
First, let‘s load the data and set up the Prophet model in Python:
import pandas as pd
from prophet import Prophet
df = pd.read_csv(‘peyton_manning.csv‘)
df.columns = [‘ds‘, ‘y‘]
df[‘ds‘] = pd.to_datetime(df[‘ds‘])
m = Prophet(changepoint_prior_scale=0.15,
seasonality_prior_scale=3,
holidays_prior_scale=0.05,
yearly_seasonality=10,
weekly_seasonality=False,
daily_seasonality=False)
Note that we set specific values for the prior scale hyperparameters to control the flexibility of each component. We also specify a high number of Fourier terms for yearly seasonality to capture the complex NFL season effects, while disabling weekly and daily seasonality.
Next, we‘ll create a custom NFL season indicator to add as a regressor, and specify the dates of Manning‘s Super Bowl appearances:
# Add NFL season regressor (September to February)
df[‘nfl_season‘] = (df.ds.dt.month < 3) | (df.ds.dt.month > 8)
# Manually specify Super Bowl dates
superbowls = pd.DataFrame({
‘ds‘: pd.to_datetime([‘2007-02-04‘, ‘2010-02-07‘,
‘2014-02-02‘, ‘2016-02-07‘]),
‘holiday‘: ‘superbowl‘
})
m.add_country_holidays(country_name=‘US‘)
m.add_regressor(‘nfl_season‘)
m.holidays = superbowls
We fit the model and generate a forecast for 365 days into the future:
m.fit(df)
future = m.make_future_dataframe(periods=365)
future[‘nfl_season‘] = (future.ds.dt.month < 3) | (future.ds.dt.month > 8)
forecast = m.predict(future)
Finally, we can plot the results:
fig = m.plot(forecast)
ax = fig.gca()
ax.set_title(‘Peyton Manning Wikipedia Page Views‘)
ax.set_xlabel(‘Date‘)
ax.set_ylabel(‘Page Views‘)
fig.tight_layout()

The model fits the historical data well and makes reasonable future forecasts. The decomposition plots show how the trend, NFL season, holidays and Super Bowl effects combine to generate the overall forecast:
fig = m.plot_components(forecast)

This example demonstrates Prophet‘s ability to flexibly incorporate domain-specific knowledge and handle multiple overlapping seasonalities and holiday effects. The resulting model provides rich explanatory insights along with an accurate forecast.
Best Practices for Prophet in Production
We have seen that Prophet can produce high-quality forecasts out of the box for a variety of time series. However, there are a number of best practices to keep in mind when using Prophet in a production setting:
- Identify the key sources of variation in your time series and explicitly model them through seasonalities, holidays, and regressors. Prophet is most effective when you can provide domain knowledge to guide the model specification.
- Use a validation set or backtesting to evaluate the model‘s performance on unseen data. Prophet includes built-in cross validation capabilities that can help with model selection.
- Adjust the trend flexibility (via
changepoint_prior_scale) and seasonality flexibility (viaseasonality_prior_scale) if the model is over- or underfitting. Higher values allow more flexibility but may lead to overfitting. - Be cautious when forecasting far into the future, especially if the forecast period extends beyond the range of the training data. Prophet‘s uncertainty intervals can help quantify the increased uncertainty associated with long-range forecasts.
- Consider modeling the individual components separately and aggregating the results, rather than fitting the aggregate series directly. This can help handle structural changes and improve interpretability.
- Prophet can struggle with very short or noisy series, as well as series with long-term dependencies beyond the seasonalities explicitly modeled. Traditional ARIMA models or more complex machine learning models may be a better fit in these cases.
Prophet is a powerful and flexible tool for time series forecasting, but it is not a silver bullet. Understanding its strengths and weaknesses is key to applying it effectively to real-world problems.
Conclusion
Facebook Prophet has emerged as a popular and powerful tool for generating accurate time series forecasts in a business setting. By combining a flexible, decomposable model with an intuitive interface and automated hyperparameter tuning, Prophet makes high-quality forecasting accessible to data scientists and analysts without extensive time series expertise.
In this post, we took a deep dive into Prophet‘s methodology and saw how it can be used to forecast complex real-world time series. We explored Prophet‘s key components and evaluated its empirical performance, and walked through a case study showing its advanced features in action. Finally, we discussed some best practices for using Prophet effectively in production settings.
Prophet is not a replacement for expert judgment or traditional statistical models, but rather a complementary tool that can improve the speed and quality of forecasting workflows. When used appropriately, it can unlock valuable insights and generate tangible business impact. As time series data continues to proliferate across industries, Prophet will no doubt remain an essential part of the modern data scientist‘s toolkit for years to come.
Additional Resources
To learn more about Prophet and time series forecasting, check out the following resources:
- Prophet Quick Start Guide
- Forecasting: Principles and Practice, a free online textbook covering a wide range of time series forecasting topics
- Time Series Forecasting with Prophet in Python, a tutorial on using Prophet for demand forecasting
- Prophet R Package Documentation
- Prophet: Forecasting at Scale, Facebook‘s blog post announcing the release of Prophet
I hope this post has given you a comprehensive overview of how to generate accurate time series forecasts with Prophet. Feel free to leave a comment below with your own experiences or insights on using Prophet in practice!