Predicting Visitors with Facebook Prophet

Facebook open sourced its forecasting tool Prohpet for time series data. Although forecasting is not a trivial task, the libraries are very easy to use and produce nice results quickly.  In this basic blog post, I am going to forecast the visitor statistics based on the historical data I collected with Piwik.

Python Prerequisites

Install and initialize a new virtual Python environment

Install Prophet and its Dependencies

Within your new Python virtual environment, install the required dependencies first and then Prophet

Get the Data from your Piwik Database

We aggregate the data from the visitors table per day and store the result in a CSV file. In the case of this blog, I started collecting visitor traffic data from early 2013. Prophet allows displaying not only trends and seasonality, but also to forecast into the future.

Usually MySQL runs with a security setting that prevents writing files to the server’s disk (for a good reason). Check the variable secure-file-priv to find the path you can use for exporting.

The data now looks similar like this:

This is exactly the format which Prophet expects.

Forecasting with Prophet

The short but nice tutorial basically shows it all. Here is the script, it is basically the very same as from the tutorial:

The results are the forecast graph and the components as nice graphs. Facebook Prophet incorporates seasonal variations, holidays and trends derived from historical data.

As you can see, the weekend is rather low on visitors and that the beginning summer is also rather weak.

 

 

2 thoughts on “Predicting Visitors with Facebook Prophet

Leave a Reply

Your email address will not be published. Required fields are marked *