FORECASTING /// TIME SERIES /// PROPHET /// PANDAS /// FORECASTING /// TIME SERIES /// PROPHET /// PANDAS /// FORECASTING ///

Prophet Library Basics

Demystify business forecasting. Learn to prepare data, handle seasonality, and predict the future with Facebook's renowned Python module.

notebook.ipynb
1 / 11
12345
📈

A.I.D.E.:Time series data is everywhere: sales, stock prices, weather. Prophet is a powerful library by Facebook designed to make forecasting accessible.


Execution Graph

UNLOCK PIPELINE NODES TO ADVANCE.

Stage 1: Formatting

Prophet needs data structured in a specific way before it can build a model.

Validation Node

Why does Prophet require renaming columns to 'ds' and 'y'?


Data Science Syndicate

Review Time Series Plots

ONLINE

Stuck on weird seasonality? Share your Matplotlib exports and get insights from the community!

Time Series Forecasting: Prophet Library Basics

Author

Pascual Vila

Lead Data Scientist // Code Syllabus

Prophet was developed by Facebook's Core Data Science team to make time series forecasting easy for analysts. It handles missing data, outliers, and holiday effects right out of the box, without requiring deep statistical expertise like ARIMA.

The Strict Prerequisite: Formatting

Unlike other Python libraries that might accept arbitrary arrays or indices, Prophet forces a standard convention. Your input Pandas DataFrame must have exactly two columns:

  • ds: The datestamp column (must be YYYY-MM-DD or YYYY-MM-DD HH:MM:SS format).
  • y: The numeric value you are trying to predict (e.g., sales, temperature, visits).

Model Initialization and Fitting

Prophet follows the widely adopted Scikit-Learn API. You initialize an instance of the Prophet() class and then call the .fit() method passing in your historical data. Under the hood, it uses Stan (a probabilistic programming language) to perform MAP (Maximum a Posteriori) estimation.

Peering into the Future

To predict, you cannot just pass a number. You must generate an empty dataframe spanning into the future using make_future_dataframe(periods=X). When you run predict(future), Prophet returns a massive dataframe containing the forecast yhat alongside confidence intervals yhat_lower and yhat_upper.

View Plotting Pro-Tip+

Built-in Visualizations: You don't need to build complex Matplotlib charts from scratch. Simply call fig1 = m.plot(forecast) to see the time series with confidence bands, and fig2 = m.plot_components(forecast) to break down the forecast into trend, weekly seasonality, and yearly seasonality.

Forecasting FAQ

Why use Prophet instead of ARIMA?

ARIMA requires data to be stationary (no trends) and equally spaced (no missing dates). It also requires manual tuning of p, d, and q parameters.

Prophet is an additive model. It works beautifully with missing data, handles dramatic trend changes (changepoints), naturally integrates holidays, and auto-detects seasonality without making the user compute differencing or stationarity.

How does Prophet handle missing data or outliers?

Because Prophet frames the forecasting problem as a curve-fitting exercise (rather than looking strictly at the time-dependence of previous points like AR models), you do not need to impute missing dates. If a date is missing, Prophet simply fits the curve around the available points. Outliers can be handled by setting their y values to NaN before fitting.

What are changepoints in Prophet?

Time series often have abrupt changes in their trajectories (e.g., a product goes viral, or a pandemic hits). Prophet automatically detects these "changepoints" in the historical data and adjusts the trend curve accordingly. You can adjust the flexibility of this by tweaking the changepoint_prior_scale parameter.

Prophet Lexicon

Prophet()
The main class imported from the library. Instantiating it creates the model object where hyperparameters can be set.
script.py
fit()
Trains the Prophet model using historical data. The input must be a Pandas DataFrame with 'ds' and 'y' columns.
script.py
make_future_dataframe()
Generates a dataframe with future dates for a specified number of periods based on the historical data's frequency.
script.py
predict()
Assigns a predicted value (yhat), as well as uncertainty intervals (yhat_lower, yhat_upper) to the future dataframe.
script.py