FB Prophet is not always the most suitable time series forecasting model
Tags: Data Science, Artificial Intelligence, Fbprophet, Time Series Forecasting, Python

FB Prophet is not always the most suitable time series forecasting model Tracyrenee Follow Jan 21 · 4 min read

I have written a series of posts about a univariate dataset of shampoo sales dating back from 1901 to 1903. This series of posts would not be complete, however, without a post on Facebook Prophet, an open source time series forecasting model. The finale of this series of posts, therefore, attempts to shed light on the forecasting of the shampoo dataset using Facebook Prophet, which is based on based on decomposable (trend+seasonality+holidays) models. The link for my most recent post on the shampoo dataset can be found here:- How statsmodels can be used to predict the sales of Shampoo

I wrote the program using Google Colab, a free online Jupyter Notebook that I was able to access on the Microsoft Edge web browser. The great thing about Google Colab is the fact it has Python and many of the libraries associated with it already installed on the platform, which means I only need to worry about writing good code.

After I created the program, I imported the libraries I would need to execute it, starting out with pandas, numpy and matplotlib.

Once I had imported the libraries, I read the csv file into the program. I obtained the shampoo dataset from Jason Brownlee’s personal GitHub account, which he has kindly shared:-

I plotted a chart of the shampoo sales over time, and it is clear that the sales were gradually increasing from the graph shown below:-

In order to get the model to accept the time series data, I converted the date to a string and then made the index a date. I then timestamped the date using the datetime() function, which became the index to the dataframe:-

I then split the series dataset into two, based upon the time series. The train dataset is 1 January 1901 to 30 July 1903, and the valid dataset is the remainder of the time series recorded, being 1 August 1903 to 31 December 1903:-

I plotted a graph of the two datasets to show how they fit in with each other:-

Because I had elected to use FB Prophet, I had to rename the columns that were going to be input into the model:-

I defined FB Prophet as the model and trained and fitted the train dataset into it before predicting on it:-

The forecast dataframe is composed of the columns:- ds, yhat, that_lower, and y_hat upper. I chose the yhat column as my prediction and was dismayed when the root mean squared error was 58,999!

I plotted the predictions on a graph against the actual values and was able to see the wide variance between the actual and predicted values from the graphical representation:-

I have kept a spreadsheet of the error based on the different models that I have used to forecast on the shampoo dataset. As can be seen from the results, Facebook Prophet fared better only to statsmodels Moving Average, which means its accuracy was very poor compared to some of the other models:-

To summarise, it is always wise, when using artificial intelligence to make predictions, to try out several models and then select the most accurate one. Sometimes it can be a huge surprise to find the model that works the best with any given dataset.

The code for this program can be found in its entirety in my personal GitHub account, the link of which is here:- Shampoo/FB_Prophet_Time_Series_Shampoo.ipynb at main · TracyRenee61/Shampoo (github.com)