Time Series Forecasting While Considering Holidays with FBProphet

Evan Budianto
3 min readDec 26, 2021
Photo by Link Hoang on Unsplash

FBProphet is a proven library for time series forecasting project. Some of its superiorities over other time series forecasting libraries include:

  • Can fit seasonal data, whether it is yearly, monthly, weekly, or even daily.
  • Can handle outliers and missing data well.
  • Easy to add special days, like holidays and user defined dates, to be considered on learning process.
  • Can handle extreme change in trend.

The library itself is very easy to be implemented and don’t need much effort to clean the data first.

In this story we will see the implementation of FBProphet on a time series forecasting case. The library will help us to predict the orders of several products from an e-commerce for a full month.

Due to its characteristic, an e-commerce can has multiple promotion on holidays and special dates like valentine or dates with repeating number, like 11–11 (11th November). This is an important information that should be considered when creating a time series prediction model.

Time Series Data

Let’s check this synthetic data of an e-commerce’s historical transaction. You can access the csv and ipynb files here.

Number of order per product for 1 Jan 2020–29 Jeb 2020

It can be seen here that campaign on repeating-number dates play a significant role on the increasing number of orders. You can see the spikes on 01–01–20 and 02–02–20. It could be the effect of massive promotion program or other marketing initiatives.

Forecasting

Using this data we are going to predict the order for every products on the last month (February 2021). The predicted number then will be compared to the actual order data on that month.

In order to do this, we need two data:

  • Historical order numbers
  • Special date reference (holiday, promo day, etc.)

First of all, we need to import the required libraries and related dataset.

Having the correct columns name is crucial here before implementing the fbprophet module on the datasets.

Then, the fitting and predicting process are quite straight forward, just like other regular machine learning libraries. We are going to do prediction on one column first.

The model can accept seasonality and holidays as its parameters. You can adjust this parameters to seek the best fitting for the model.

The predicted value can be plotted directly from the model:

The dots represent the actual data while the line represent fitting and predicting result

You can see the model has predicted the orders for the next one month (February 2021).

The model can also shows related information from the data such as:

  • general trend
  • effect of special dates on order numbers
  • weekly/yearly seasonality

Measuring Errors

To measure the errors between predicted results and the actual data, we are going to use MAPE and MAE.

You can that there is gap between actual and predicted values, especially on dates where the number of orders are actually very high.

Actual data (orange) vs predicted data (blue)

On this phase, you can try to improve your model to fit the data better by doing hyperparameter tuning. Then, you can apply the process to the other remaining columns.

Summary

FBProphet is a very powerful yet easy to use library for time series forecasting. The key to have the best result from this algorithm is to understand your data first and then bring out its characteristic as parameters for fitting, like seasonality, holidays, etc.

--

--

Evan Budianto

I just imported pandas and numpy then called myself a data scientist. Writing what I learned about data science.