Facebook’s Prophet Model for Time Series Forecasting

Aadhil imam
4 min readDec 31, 2020

In this article I am going to examine what is Time series forecasting and how cloud do time series forecasting using Facebook prophet.Time-series forecasting is one of the important areas of machine learning. This is very important when it comes to prediction problems that involve a time component.

What is Time Series Forecasting

Time series forecasting is a technique for the prediction of events through a sequence of time. The technique is used across many fields of study, from the geology to behavior to economics. The techniques predict future events by analyzing the trends of the past, on the assumption that future trends will hold similar to historical trends.

Time series analysis is basically the recording of data at a regular interval of time, which could lead to taking a versed decision, crucial for trade and so have multiple applications such as Stock Market and Trends analysis, Financial forecasting, Inventory analysis, Census Analysis, Yield prediction, Sales forecasting, etc.

Applications of Time series forecasting

Time-series forecasting is widely used for non-stationary data. Non-stationary data are called the data whose statistical properties e.g. the mean and standard deviation are not constant over time but instead, these metrics vary over time.These non-stationary input data are usually called time-series.

If you need to learn more about time series forecasting refer using this link

Prophet for forecasting

Prophet is open source software released by Facebook’s Core Data Science team.Prophet is a procedure for forecasting time series data based on an additive model where non-linear trends are fit with yearly, weekly, and daily seasonality, plus holiday effects. It works best with time series that have strong seasonal effects and several seasons of historical data. Prophet is robust to missing data and shifts in the trend, and typically handles outliers well.

Main four features of Prophet.

  1. Accurate and fast.
  2. Fully automatic.
  3. Tunable forecasts.
  4. Available in R or Python

So lets start a small time series forecasting using python Facebook prophet API.first of all we need to install Facebook prophet package so you can installed using pip in Python as shown below.

pip install fbprophet

The dataset I have used for this tutorial is available here.Let’s start by reading in our time series data. We can load the dataset and print out the first 5 row with the below code

now lets plot the time series data using matplotlib library as line plot.

New lets fit time series data to the model.We start by creating an instance of the Prophet class and then fit it to our dataset , you can see the code below.

The next step is to prepare our model to make future predictions. This is achieved using the Prophet.make_future_dataframe method and passing the number of days to predict in the future. We use the periods attribute to specify this.

In the code chunk above, we instructed Prophet to generate 365 datestamps in the future.

after that use the predict method to make future predictions. This will generate a dataframe with a yhat column that will contain the predictions.Prophet returns a large DataFrame with many interesting columns, but we subset our output to the columns most relevant to forecasting.

How ever we need ds, yhat, yhat_lower and yhat_upper. yhat is our predicted forecast, yhat_lower is the lower bound for our predictions and yhat_upper is the upper bound for our predictions.

  • ds : the datestamp of the forecasted value
  • yhat: the forecasted value of our metric (in Statistics, yhat is a notation traditionally used to represent the predicted values of a value y)
  • yhat_lower : the lower bound of our forecasts
  • yhat_upper : the upper bound of our forecasts

Now lets plot the time series forecast, Prophet has an inbuilt feature that enables us to plot the forecasts we just generated. This is achieved using mode.plot() and passing in our forecasts as the argument.

Forecast

As above picture you can see Prophet plots the observed values of our time series (the black dots), the forecasted values (blue line) and the uncertainty intervals of our forecasts (the blue shaded regions).

Finally prophet has strong feature ability to return the components of our forecasts using plot_components method. Its plots the trend, yearly and weekly seasonality of the time series data.

Plotting the Forecast Components

As conclusion Prophet is very powerful and effective in time series forecasting.In particular, Prophet provides the functionality to bring your own knowledge about time series to the table.

--

--