Sales Forecasting using Prophet Time Series Analysis with Python

Sales forecasting is a common task in most sales driven organizations. A good forecast allows firms to adequately plan and manage their short and long-term goals, with a degree of confidence. It also allows leaders to establish and allocate the right targets to their teams and encourages sales teams to develop a healthy pipeline of opportunities to achieve their goals.

It’s also hard to get precise forecasts. In most businesses, sales is a function of many attributes, both macro (e.g. inflation, consumer sentiment, employment rates, gdp etc) and micro (e.g firm’s products, capabilities, consumer demand, marketing efforts, incentives etc). It’s possible to develop complex models to capture all these variables, however, for managerial decision making, a simpler, easy to understand model often works better.

In this very practical example, we are going to use time series analysis, to derive meaningful insights from past observed data, and use it to predict future values, without worry too much about intrinsic factors.

Broadly, here are the steps

  1. Establish a top level goal for the firm/ business unit/ team. This could in the form of annual business plan

  2. Prepare historical data of past performances. e.g. Sales data for your product by time

  3. Perform time series analysis to understand general trend and seasonality

  4. Use a time series model to predict future values

  5. Evaluate the forecast accuracy / usability based on some predefined performance metric

  6. Review one-off historical outliers and understand what caused them, and whether they will repeat again (e.g. product deprecation, hike in GST, natural disaster! etc)

  7. Review the gap between the top level goals and the final forecast. This gap indicates additional effort needed by your organization to achieve your overall goals. This could be through product improvements, more sales and marketing efforts, pricing, distribution etc.

For the purpose of this exercise, we will use a publicly available Superstore dataset from tableau. It contains data for a retail store like a Walmart with branches across the US from 1/3/14 to 12/30/17. We will forecast Sales for 2018, for the Furniture category.

There are many time series techniques available. We will use Facebook’s Prophet.

#1. Establish a top level Business goal for the year

Let’s assume that management / finance looked at historical growth for the Furniture category, and came to the conclusion that it will continue to grow linearly, and set a 10% YoY growth target in 2018 ~$236,243. Our task now is to figure out whether this is achievable, how to allocate this by month and quarter, and what additional sales do we need to drive beyond just seasonality.

2018 Projections using simple linear forecast

2018 Projections using simple linear forecast

#2. Prepare date for analysis and forecasting

For the rest of this article, we will use Google Colab

!pip install fbprophet #install prophet packages
!pip install --upgrade pandas  #prophet requires a slightly updated version of pandas missing in Google colab