Sign up for my newsletter and get my free intro class:
Let's talk about forecasting demand, this is as old as money and commerce. Rainy season, you stock up on umbrellas; winter, winter coats, etc. I'll walk you through a simple example using open-source FBProphet in Python, one of the most powerful forecasting engines and also one of the easiest to use (once you manage to install it).
from IPython.display import Image Image(filename='Forecasting-Demand.png')
Forecasting Online Interest and Demand¶
Let's talk about forecasting demand, this is as old as money and commerce. Rainy seasons you stock up on umbrellas, for winter, winter coats, etc. It is also critical today, where so many stores around the world are closed due to covid19 and want an online presence, a virtual store to mirror Amazon and the likes. And most products aren't as straightforward as selling umbrellas.
I'll walk you through a simple example using open-source FBProphet in Python, one of the most powerful forecasting engines and also one of the easiest to use (once you manage to install it). I'll also show you external data sources that work great as proxy values to forecast demand when you want to understand products you don't carry or you don't have enough data stored.
To properly forecast demand you need enough data to teach a model the different cycles and season around that product, preferably a few of those cycles. FBProphet recommends 3 years of data so the model can understand the different holidays, peak sales, low sales, etc.
Let me show you an example using anonymized data from a Kaggle competition the "Store Item Demand Forecasting Challenge"
Open Source FBProphet¶
"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"
"It works best with time series that have strong seasonal effects and several seasons of historical data."
"Prophet is used in many applications across Facebook for producing reliable forecasts for planning and goal setting. We’ve found it to perform better than any other approach in the majority of cases."
FBProphet Quick Start Guide¶
Installing FB Prophet:¶
!pip3 install fbprophet --user
!pip3 install holidays==0.9.12
import time import matplotlib import matplotlib.pyplot as plt import seaborn as sns import statsmodels.api as sm import io, base64, os, json, re, glob import datetime from datetime import timedelta import pandas as pd import pydata_google_auth import numpy as np from fbprophet import Prophet import statsmodels.api as sm
df_raw = pd.read_csv('demand-forecasting-kernels-only/train.csv', low_memory=False, parse_dates=['date'], index_col=['date'])
df_raw = df_raw.sort_values('date', ascending=True) print(df_raw.shape) df_raw.head()
plt.subplots(1, figsize = (16, 5)) plt.grid() plt.title('Store 1 - All Sales') for item in set(df_raw[df_raw['store'] == 1]['item']): plt.plot(df_raw[(df_raw['store'] == 1) & (df_raw['item'] == item)]['sales'].rolling(window=50).mean())