Fine Grained Demand Forecasting(Python)

Demand Forecasting

The objective of this notebook is to illustrate how we might generate a large number of fine-grained forecasts at the store-item level in an efficient manner leveraging the distributed computational power of Databricks. For this exercise, we will make use of an increasingly popular library for demand forecasting, FBProphet, which we will load into the notebook session associated with a cluster running Databricks 6.0 or higher:

# load fbprophet library
dbutils.library.installPyPI('FBProphet', version='0.5') # find latest version of fbprophet here: https://pypi.org/project/fbprophet/
dbutils.library.installPyPI('holidays','0.9.12') # this line is in response to this issue with fbprophet 0.5: https://github.com/facebook/prophet/issues/1293

dbutils.library.restartPython()
Show result

Examine the Data

For our training dataset, we will make use of 5-years of store-item unit sales data for 50 items across 10 different stores. This data set is publicly available as part of a past Kaggle competition and can be downloaded here.

Once downloaded, we can uzip the train.csv.zip file and upload the decompressed CSV to /FileStore/tables/demand_forecast/train/ using the file import steps documented here. Please note when performing the file import, you don't need to select the Create Table with UI or the Create Table in Notebook options to complete the import process.

With the dataset accessible within Databricks, we can now explore it in preparation for modeling:

from pyspark.sql.types import *

# structure of the training data set
train_schema = StructType([
  StructField('date', DateType()),
  StructField('store', IntegerType()),
  StructField('item', IntegerType()),
  StructField('sales', IntegerType())
  ])

# read the training file into a dataframe
train = spark.read.csv(
  '/FileStore/tables/demand_forecast/train/train.csv', 
  header=True, 
  schema=train_schema
  )

# make the dataframe queriable as a temporary view
train.createOrReplaceTempView('train')

When performing demand forecasting, we are often interested in general trends and seasonality. Let's start our exploration by examing the annual trend in unit sales:

%sql

SELECT
  year(date) as year, 
  sum(sales) as sales
FROM train
GROUP BY year(date)
ORDER BY year;
year2.013k2.014k2.015k2.016k2.017k8.0M8.5M9.0M9.5M10M11Msalessales

It's very clear from the data that there is a generally upward trend in total unit sales across the stores. If we had better knowledge of the markets served by these stores, we might wish to identify whether there is a maximum growth capacity we'd expect to approach over the life of our forecast. But without that knowledge and by just quickly eyeballing this dataset, it feels safe to assume that if our goal is to make a forecast a few days, months or even a year out, we might expect continued linear growth over that time span.

Now let's examine seasonality. If we aggregate the data around the individual months in each year, a distinct yearly seasonal pattern is observed which seems to grow in scale with overall growth in sales:

%sql

SELECT 
  TRUNC(date, 'MM') as month,
  SUM(sales) as sales
FROM train
GROUP BY TRUNC(date, 'MM')
ORDER BY month;
month201320152017600k800k1.0Msalessales

Aggregating the data at a weekday level, a pronounced weekly seasonal pattern is observed with a peak on Sunday (weekday 0), a hard drop on Monday (weekday 1) and then a steady pickup over the week heading back to the Sunday high. This pattern seems to be pretty stable across the five years of observations:

%sql

SELECT
  YEAR(date) as year,
  CAST(DATE_FORMAT(date, 'u') as Integer) % 7 as weekday,
  --CONCAT(DATE_FORMAT(date, 'u'), '-', DATE_FORMAT(date, 'EEEE')) as weekday,
  AVG(sales) as sales
FROM (
  SELECT 
    date,
    SUM(sales) as sales
  FROM train
  GROUP BY date
 ) x
GROUP BY year, CAST(DATE_FORMAT(date, 'u') as Integer) --, CONCAT(DATE_FORMAT(date, 'u'), '-', DATE_FORMAT(date, 'EEEE'))
ORDER BY year, weekday;
weekday024620k25k30kyear2013201320142014201520152016201620172017

Now that we are oriented to the basic patterns within our data, let's explore how we might build a forecast.

Build a Forecast

Before attempting to generate forecasts for individual combinations of stores and items, it might be helpful to build a single forecast for no other reason than to orient ourselves to the use of FBProphet.

Our first step is to assemble the historical dataset on which we will train the model:

# query to aggregate data to date (ds) level
sql_statement = '''
  SELECT
    CAST(date as date) as ds,
    sales as y
  FROM train
  WHERE store=1 AND item=1
  ORDER BY ds
  '''

# assemble dataset in Pandas dataframe
history_pd = spark.sql(sql_statement).toPandas()

# drop any missing records
history_pd = history_pd.dropna()

Now, we will import the fbprophet library, but because it can be a bit verbose when in use, we will need to fine-tune the logging settings in our environment:

from fbprophet import Prophet
import logging

# disable informational messages from fbprophet
logging.getLogger('py4j').setLevel(logging.ERROR)
Show result

Based on our review of the data, it looks like we should set our overall growth pattern to linear and enable the evaluation of weekly and yearly seasonal patterns. We might also wish to set our seasonality mode to multiplicative as the seasonal pattern seems to grow with overall growth in sales:

# set model parameters
model = Prophet(
  interval_width=0.95,
  growth='linear',
  daily_seasonality=False,
  weekly_seasonality=True,
  yearly_seasonality=True,
  seasonality_mode='multiplicative'
  )

# fit the model to historical data
model.fit(history_pd)
Out[4]: <fbprophet.forecaster.Prophet at 0x7f78238fef98>

Now that we have a trained model, let's use it to build a 90-day forecast:

# define a dataset including both historical dates & 90-days beyond the last available date
future_pd = model.make_future_dataframe(
  periods=90, 
  freq='d', 
  include_history=True
  )

# predict over the dataset
forecast_pd = model.predict(future_pd)

display(forecast_pd)
2013-01-01T00:00:00.000+000015.6031397157683062.08538716128920318.27389292766186215.60313971576830615.603139715768306-0.356023317327815-0.356023317327815-0.356023317327815-0.08884753072620905-0.08884753072620905-0.08884753072620905-0.2671757866016059-0.2671757866016059-0.267175786601605900010.048058153431093
2013-01-02T00:00:00.000+000015.6088362364873532.223031575914137518.74904883789094615.60883623648735315.608836236487353-0.3256699666337138-0.3256699666337138-0.3256699666337138-0.05903196920294723-0.05903196920294723-0.05903196920294723-0.26663799743076655-0.26663799743076655-0.2666379974307665500010.525507060159415
2013-01-03T00:00:00.000+000015.6145327572063982.366741178374732518.7209933806309515.61453275720639815.614532757206398-0.29230176164020893-0.29230176164020893-0.29230176164020893-0.025389716700157106-0.025389716700157106-0.025389716700157106-0.26691204494005183-0.26691204494005183-0.2669120449400518300011.050377325086219
2013-01-04T00:00:00.000+000015.6202292779254463.67041534825593820.69554214664723415.62022927792544615.620229277925446-0.21629242102190085-0.21629242102190085-0.216292421021900850.0516661472125918150.0516661472125918150.051666147212591815-0.26795856823449266-0.26795856823449266-0.2679585682344926600012.241692070485774
2013-01-05T00:00:00.000+000015.6259257986444914.754185207253523.4139426987195415.62592579864449115.625925798644491-0.11826586296454089-0.11826586296454089-0.118265862964540890.15144848948283090.15144848948283090.1514484894828309-0.2697143524473718-0.2697143524473718-0.269714352447371800013.777912199447918
2013-01-06T00:00:00.000+000015.6316223193635384.95889391627316922.2072763586560115.63162231936353815.631622319363538-0.08027841922546172-0.08027841922546172-0.080278419225461720.191816570928910440.191816570928910440.19181657092891044-0.27209499015437216-0.27209499015437216-0.2720949901543721600014.376740389635588
2013-01-07T00:00:00.000+000015.637318840082584-0.224113077041262516.8225226029104115.63731884008258415.637318840082584-0.4966600410582783-0.4966600410582783-0.4966600410582783-0.2216619909945789-0.2216619909945789-0.2216619909945789-0.27499805006369943-0.27499805006369943-0.274998050063699430007.870887422925779
2013-01-08T00:00:00.000+000015.6430153608016321.283028948380854618.87734702482841315.64301536080163215.643015360801632-0.3671541874581153-0.3671541874581153-0.3671541874581153-0.08884753072617603-0.08884753072617603-0.08884753072617603-0.2783066567319393-0.2783066567319393-0.27830665673193930009.899616766611693
2013-01-09T00:00:00.000+000015.648711881520681.162037231588766219.09868269039199315.6487118815206815.64871188152068-0.3409253446436948-0.3409253446436948-0.3409253446436948-0.05903196920326247-0.05903196920326247-0.05903196920326247-0.2818933754404323-0.2818933754404323-0.281893375440432300010.313669390083358
2013-01-10T00:00:00.000+000015.6544084022397242.320420718265170419.05940306853892715.65440840223972415.654408402239724-0.3110140064594736-0.3110140064594736-0.3110140064594736-0.02538971670085523-0.02538971670085523-0.02538971670085523-0.2856242897586183-0.2856242897586183-0.285624289758618300010.785668126306302
2013-01-11T00:00:00.000+000015.6601049229587732.62229503065881820.44253253547343315.66010492295877315.660104922958773-0.23769700865302526-0.23769700865302526-0.237697008653025260.051666147212316780.051666147212316780.05166614721231678-0.28936315586534206-0.28936315586534206-0.2893631558653420600011.937744827578959
2013-01-12T00:00:00.000+000015.6658014436778185.02553173643130321.52127114979269615.66580144367781815.665801443677818-0.14152702797717923-0.14152702797717923-0.141527027977179230.15144848948261240.15144848948261240.1514484894826124-0.2929755174597916-0.2929755174597916-0.292975517459791600013.448667124473493
2013-01-13T00:00:00.000+000015.6714979643968675.59347044965570822.81065104159015215.67149796439686715.671497964396867-0.10451609710904568-0.10451609710904568-0.104516097109045680.191816570929280340.191816570929280340.19181657092928034-0.29633266803832603-0.29633266803832603-0.2963326680383260300014.033574161305753
2013-01-14T00:00:00.000+000015.677194485115912-0.916919573636172815.5566127184291815.67719448511591215.677194485115912-0.5209773443231122-0.5209773443231122-0.5209773443231122-0.22166199099439837-0.22166199099439837-0.22166199099439837-0.29931535332871384-0.29931535332871384-0.299315353328713840007.509731335823284
2013-01-15T00:00:00.000+000015.6828910058349591.16870082169332617.2263081746727515.68289100583495915.682891005834959-0.39066464628314507-0.39066464628314507-0.39066464628314507-0.08884753072614303-0.08884753072614303-0.08884753072614303-0.301817115557002-0.301817115557002-0.3018171155570020009.556139938343327
2013-01-16T00:00:00.000+000015.6885875265540081.036869502366450318.2733791496695415.68858752655400815.688587526554008-0.3627791619002906-0.3627791619002906-0.3627791619002906-0.059031969203577714-0.059031969203577714-0.059031969203577714-0.30374719269671285-0.30374719269671285-0.303747192696712850009.997094892271392
2013-01-17T00:00:00.000+000015.6942840472730532.143334315124881619.45622422226536215.69428404727305315.694284047273053-0.33042261627094044-0.33042261627094044-0.33042261627094044-0.025389716700458746-0.025389716700458746-0.025389716700458746-0.3050328995704817-0.3050328995704817-0.305032899570481700010.508537651873805
2013-01-18T00:00:00.000+000015.69998056799212.58498184222103320.47881119756695515.699980567992115.6999805679921-0.2539552860204286-0.2539552860204286-0.25395528602042860.051666147212216090.051666147212216090.05166614721221609-0.3056214332326447-0.3056214332326447-0.305621433232644700011.712887512332495
2013-01-19T00:00:00.000+000015.7056770887111454.45889670167546821.89259112258790615.70567708871114515.705677088711145-0.15403257252457903-0.15403257252457903-0.154032572524579030.151448489482599370.151448489482599370.15144848948259937-0.3054810620071784-0.3054810620071784-0.305481062007178400013.286491243496625
2013-01-20T00:00:00.000+000015.7113736094301935.10379374099861522.8511978484779815.71137360943019315.711373609430193-0.11278510447241799-0.11278510447241799-0.112785104472417990.19181657092895610.19181657092895610.1918165709289561-0.30460167540137406-0.30460167540137406-0.3046016754013740600013.939364695485418
2013-01-21T00:00:00.000+000015.71707013014924-0.929679284808322516.76712576396474215.7170701301492415.71707013014924-0.5246566813502829-0.5246566813502829-0.5246566813502829-0.22166199099444836-0.22166199099444836-0.22166199099444836-0.30299469035583454-0.30299469035583454-0.302994690355834540007.471004275115481
2013-01-22T00:00:00.000+000015.7227666508682860.78194856625698317.9339221286939215.72276665086828615.722766650868286-0.3895398581385614-0.3895398581385614-0.3895398581385614-0.08884753072581252-0.08884753072581252-0.08884753072581252-0.3006923274127489-0.3006923274127489-0.30069232741274890009.59812236014335
2013-01-23T00:00:00.000+000015.7284631715873341.853215868224737718.59660143663273515.72846317158733415.728463171587334-0.35677825708802763-0.35677825708802763-0.35677825708802763-0.059031969203084345-0.059031969203084345-0.059031969203084345-0.2977462878849433-0.2977462878849433-0.297746287884943300010.116889494555174
2013-01-24T00:00:00.000+000015.734159692306381.596569339846624719.34413141275966615.7341596923063815.73415969230638-0.31961559620595204-0.31961559620595204-0.31961559620595204-0.025389716700465095-0.025389716700465095-0.025389716700465095-0.29422587950548695-0.29422587950548695-0.2942258795054869500010.705276861450217
2013-01-25T00:00:00.000+000015.7398562130254263.45590870723910520.14703932012311315.73985621302542615.739856213025426-0.23854950567553268-0.23854950567553268-0.238549505675532680.0516661472124584350.0516661472124584350.051666147212458435-0.2902156528879911-0.2902156528879911-0.290215652887991100011.98512129400425
2013-01-26T00:00:00.000+000015.7455527337444714.9216734507687321.7610164532013615.74555273374447115.745552733744471-0.13436413455088358-0.13436413455088358-0.134364134550883580.151448489482586380.151448489482586380.15144848948258638-0.28581262403346996-0.28581262403346996-0.2858126240334699600013.629915167649596
2013-01-27T00:00:00.000+000015.751249254463525.56676120448678522.70316222389364215.7512492544635215.75124925446352-0.0893065978148497-0.0893065978148497-0.08930659781484970.191816570928984580.191816570928984580.19181657092898458-0.28112316874383425-0.28112316874383425-0.2811231687438342500014.344558772213695
2013-01-28T00:00:00.000+000015.7569457751825690.2475556443489492516.84508597816984515.75694577518256915.756945775182569-0.49792167386713804-0.49792167386713804-0.49792167386713804-0.2216619909942679-0.2216619909942679-0.2216619909942679-0.2762596828728701-0.2762596828728701-0.27625968287287010007.911220959769935
2013-01-29T00:00:00.000+000015.7626422959016141.440820020501669718.6153014962868215.76264229590161415.762642295901614-0.3601846383945885-0.3601846383945885-0.3601846383945885-0.08884753072605686-0.08884753072605686-0.08884753072605686-0.27133710766853164-0.27133710766853164-0.2713371076685316400010.085180680409046
2013-01-30T00:00:00.000+000015.768338816620661.735085168980310819.9027150033097515.7683388166206615.76833881662066-0.3255013911221756-0.3255013911221756-0.3255013911221756-0.05903196920339958-0.05903196920339958-0.05903196920339958-0.266469421918776-0.266469421918776-0.26646942191877600010.635722596124836
2013-01-31T00:00:00.000+000015.7740353373397062.473724116969630719.2679782423074915.77403533733970615.774035337339706-0.2871559188716555-0.2871559188716555-0.2871559188716555-0.025389716700068614-0.025389716700068614-0.025389716700068614-0.26176620217158686-0.26176620217158686-0.2617662021715868600011.244427725731958
2013-02-01T00:00:00.000+000015.7797318580587554.11586441214200821.84209960590599715.77973185805875515.779731858058755-0.20566320179520312-0.20566320179520312-0.205663201795203120.0516661472127007760.0516661472127007760.051666147212700776-0.2573293490079039-0.2573293490079039-0.257329349007903900012.534421680660621
2013-02-02T00:00:00.000+000015.78542837877785.50247138892961422.6189326837723215.785428378777815.7854283787778-0.10180158184612709-0.10180158184612709-0.101801581846127090.151448489482958360.151448489482958360.15144848948295836-0.25325007132908545-0.25325007132908545-0.2532500713290854500014.178446799699474
2013-02-03T00:00:00.000+000015.7911248994968476.75782933231225823.77026971200483315.79112489949684715.791124899496847-0.057789641153088545-0.057789641153088545-0.0577896411530885450.191816570929178120.191816570929178120.19181657092917812-0.24960621208226666-0.24960621208226666-0.2496062120822666600014.878561458151323
2013-02-04T00:00:00.000+000015.796821420215895-0.3834174879028318716.88030782094331515.79682142021589515.796821420215895-0.4681219790543056-0.4681219790543056-0.4681219790543056-0.2216619909943851-0.2216619909943851-0.2216619909943851-0.24645998805992045-0.24645998805992045-0.246459988059920450008.401982114216983
2013-02-05T00:00:00.000+000015.802517940934942.664386243926772519.1308334544343315.8025179409349415.80251794093494-0.33270373443041257-0.33270373443041257-0.33270373443041257-0.08884753072602387-0.08884753072602387-0.08884753072602387-0.24385620370438874-0.24385620370438874-0.2438562037043887400010.544961208582292
2013-02-06T00:00:00.000+000015.8082144616539872.429059420118310419.4636935133156815.80821446165398715.808214461653987-0.3008529538125736-0.3008529538125736-0.3008529538125736-0.05903196920324601-0.05903196920324601-0.05903196920324601-0.2418209846093276-0.2418209846093276-0.241820984609327600011.052266446362742
2013-02-07T00:00:00.000+000015.8139109823730334.1168677807740719.72239581524721815.81391098237303315.813910982373033-0.26575077775851114-0.26575077775851114-0.26575077775851114-0.025389716700766736-0.025389716700766736-0.025389716700766736-0.24036106105774438-0.24036106105774438-0.2403610610577443800011.61135183940354
2013-02-08T00:00:00.000+000015.8196075030920815.072598613664721.49961832219591815.81960750309208115.819607503092081-0.18779746870803457-0.18779746870803457-0.187797468708034570.051666147212082720.051666147212082720.05166614721208272-0.2394636159201173-0.2394636159201173-0.239463615920117300012.848725258056756
2013-02-09T00:00:00.000+000015.8253040238111265.75368895478170422.4396531754309515.82530402381112615.825304023811126-0.08764820553609508-0.08764820553609508-0.087648205536095080.151448489482354840.151448489482354840.15144848948235484-0.2390966950184499-0.2390966950184499-0.239096695018449900014.438244524060936
2013-02-10T00:00:00.000+000015.8310005445301755.54667505439540923.86459456302359415.83100054453017515.831000544530175-0.04739359117484124-0.04739359117484124-0.047393591174841240.191816570929371650.191816570929371650.19181657092937165-0.2392101621042129-0.2392101621042129-0.239210162104212900015.080712576834024
2013-02-11T00:00:00.000+000015.836697065249222-0.384258922292144817.27244000595831615.83669706524922215.836697065249222-0.46139915634646367-0.46139915634646367-0.46139915634646367-0.22166199099450232-0.22166199099450232-0.22166199099450232-0.23973716535196135-0.23973716535196135-0.239737165351961350008.529658400028714
2013-02-12T00:00:00.000+000015.8423935859682672.389257045515309518.9414167461689915.84239358596826715.842393585968267-0.3294435988836599-0.3294435988836599-0.3294435988836599-0.08884753072599086-0.08884753072599086-0.08884753072599086-0.2405960681576691-0.2405960681576691-0.240596068157669100010.62321842807547
2013-02-13T00:00:00.000+000015.8480901066873162.534238491290698619.59134355767550815.84809010668731615.848090106687316-0.3007247536444713-0.3007247536444713-0.3007247536444713-0.059031969203092435-0.059031969203092435-0.059031969203092435-0.24169278444137887-0.24169278444137887-0.2416927844413788700011.08217711361839
2013-02-14T00:00:00.000+000015.8537866274063613.291503843662218419.89220733319534815.85378662740636115.853786627406361-0.2683131646241628-0.2683131646241628-0.2683131646241628-0.025389716700298017-0.025389716700298017-0.025389716700298017-0.2429234479238648-0.2429234479238648-0.242923447923864800011.600006966130728
2013-02-15T00:00:00.000+000015.8594831481254084.01211388246711821.65347784935205815.85948314812540815.859483148125408-0.19251118904858494-0.19251118904858494-0.192511189048584940.051666147212842440.051666147212842440.05166614721284244-0.24417733626142737-0.24417733626142737-0.2441773362614273700012.806355189583792
2013-02-16T00:00:00.000+000015.8651796688444575.92980888363063722.93829937792454715.86517966884445715.865179668844457-0.09389147521449032-0.09389147521449032-0.093891475214490320.151448489482726820.151448489482726820.15144848948272682-0.24533996469721714-0.24533996469721714-0.2453399646972171400014.375574545193711
2013-02-17T00:00:00.000+000015.8708761895635027.10432825842107423.76535287662887415.87087618956350215.870876189563502-0.05447968924031418-0.05447968924031418-0.054479689240314180.191816570929223770.191816570929223770.19181657092922377-0.24629626016953796-0.24629626016953796-0.2462962601695379600015.00623578678458
2013-02-18T00:00:00.000+000015.876572710282549-0.1679219605638301917.39958858459803215.87657271028254915.876572710282549-0.46859571667783595-0.46859571667783595-0.46859571667783595-0.22166199099461956-0.22166199099461956-0.22166199099461956-0.24693372568321645-0.24693372568321645-0.246933725683216450008.436878742719925
2013-02-19T00:00:00.000+000015.8822692310015941.784478925680233818.8302904747534715.88226923100159415.882269231001594-0.3359930369212351-0.3359930369212351-0.3359930369212351-0.08884753072593776-0.08884753072593776-0.08884753072593776-0.24714550619529735-0.24714550619529735-0.2471455061952973500010.545937358876678
2013-02-20T00:00:00.000+000015.8879657517206433.064742936440504619.55111353954019315.88796575172064315.887965751720643-0.30586524042350594-0.30586524042350594-0.30586524042350594-0.05903196920306788-0.05903196920306788-0.05903196920306788-0.24683327122043805-0.24683327122043805-0.2468332712204380500011.02838928723018
2013-02-21T00:00:00.000+000015.8936622724396883.127526444103086820.12770448527843615.89366227243968815.893662272439688-0.27129955237496595-0.27129955237496595-0.27129955237496595-0.025389716699901536-0.025389716699901536-0.025389716699901536-0.24590983567506441-0.24590983567506441-0.2459098356750644100011.581718812327916
2013-02-22T00:00:00.000+000015.8993587931587364.63474877943802621.37898731035543815.89935879315873615.899358793158736-0.1926353017325368-0.1926353017325368-0.19263530173253680.051666147212567410.051666147212567410.05166614721256741-0.24430144894510422-0.24430144894510422-0.2443014489451042200012.83658101468474
2013-02-23T00:00:00.000+000015.9050553138777835.74952923157447722.67274148789039515.90505531387778315.905055313877783-0.0905012030227745-0.0905012030227745-0.09050120302277450.15144848948271380.15144848948271380.1514484894827138-0.2419496925054883-0.2419496925054883-0.241949692505488300014.465628673828071
2013-02-24T00:00:00.000+000015.9107518345968287.21381391442514623.39424182008461315.91075183459682815.910751834596828-0.046996367393893554-0.046996367393893554-0.0469963673938935540.191816570929593640.191816570929593640.19181657092959364-0.2388129383234872-0.2388129383234872-0.238812938323487200015.16300429586505
2013-02-25T00:00:00.000+000015.916448355315877-0.523215404292290317.54013730903039615.91644835531587715.916448355315877-0.4565293243713464-0.4565293243713464-0.4565293243713464-0.2216619909944391-0.2216619909944391-0.2216619909944391-0.23486733337690735-0.23486733337690735-0.234867333376907350008.650122941272093
2013-02-26T00:00:00.000+000015.9221448760349223.113175197219429719.33603771813156415.92214487603492215.922144876034922-0.3189548202497031-0.3189548202497031-0.3189548202497031-0.08884753072620223-0.08884753072620223-0.08884753072620223-0.2301072895235009-0.2301072895235009-0.230107289523500900010.843700019109471
2013-02-27T00:00:00.000+000015.927841396753973.055689248066590519.9400156751691715.9278413967539715.92784139675397-0.283577441460522-0.283577441460522-0.283577441460522-0.05903196920351214-0.05903196920351214-0.05903196920351214-0.22454547225700985-0.22454547225700985-0.2245454722570098500011.411064885473492
2013-02-28T00:00:00.000+000015.9335379174730183.817738424007687520.98956407088424615.93353791747301815.933537917473018-0.24360201286548663-0.24360201286548663-0.24360201286548663-0.025389716700599658-0.025389716700599658-0.025389716700599658-0.218212296164887-0.218212296164887-0.21821229616488700012.052096008708036
2013-03-01T00:00:00.000+000015.9392344390259564.78654260500882522.11668891307425615.93923443902595615.939234439025956-0.15948880153657358-0.15948880153657358-0.159488801536573580.051666147212809750.051666147212809750.05166614721280975-0.21115494874938334-0.21115494874938334-0.2111549487493833400013.397105040935227
2013-03-02T00:00:00.000+000015.9449309605788966.72123090752440623.53576897133285315.94493096057889615.944930960578896-0.051987487815955725-0.051987487815955725-0.0519874878159557250.151448489482495290.151448489482495290.15144848948249529-0.203435977298451-0.203435977298451-0.20343597729845100015.115994056539545
2013-03-03T00:00:00.000+000015.9506274821318367.92580256437492224.2368653837287115.95062748213183615.950627482131836-0.0033149143993382035-0.0033149143993382035-0.00331491439933820350.191816570929445760.191816570929445760.19181657092944576-0.19513148532878397-0.19513148532878397-0.1951314853287839700015.897752517412838
2013-03-04T00:00:00.000+000015.9563240036847741.319007002469761317.6307081305186315.95632400368477415.956324003684774-0.4079909864440093-0.4079909864440093-0.4079909864440093-0.22166199099448908-0.22166199099448908-0.22166199099448908-0.1863289954495202-0.1863289954495202-0.18632899544952020009.4462876334012
2013-03-05T00:00:00.000+000015.9620205252377142.882745776416749520.29489950451831615.96202052523771415.962020525237714-0.26597257475708436-0.26597257475708436-0.26597257475708436-0.08884753072587175-0.08884753072587175-0.08884753072587175-0.1771250440312126-0.1771250440312126-0.177125044031212600011.716560827814812
2013-03-06T00:00:00.000+000015.9677170467906543.73896203005755920.6597959327884415.96771704679065415.967717046790654-0.2266545487968697-0.2266545487968697-0.2266545487968697-0.05903196920335857-0.05903196920335857-0.05903196920335857-0.16762257959351112-0.16762257959351112-0.1676225795935111200012.348561344234234
2013-03-07T00:00:00.000+000015.9734135683435923.764067079757401421.65625366003497415.97341356834359215.973413568343592-0.18331795788370597-0.18331795788370597-0.18331795788370597-0.02538971670013094-0.02538971670013094-0.02538971670013094-0.15792824118357504-0.15792824118357504-0.1579282411835750400013.045200012562963
2013-03-08T00:00:00.000+000015.9791100898965315.37676221197510823.0292305749039115.97911008989653115.979110089896531-0.09648344790146991-0.09648344790146991-0.096483447901469910.051666147212191690.051666147212191690.05166614721219169-0.1481495951136616-0.1481495951136616-0.148149595113661600014.437390454026147
2013-03-09T00:00:00.000+000015.9848066114494738.19424521693004624.99736623131814315.98480661144947315.9848066114494730.0130560812515449070.0130560812515449070.0130560812515449070.151448489482276740.151448489482276740.15144848948227674-0.13839240823073184-0.13839240823073184-0.1383924082307318400016.193505545358793
2013-03-10T00:00:00.000+000015.9905031330024138.66110879830314125.1806756023610215.99050313300241315.9905031330024130.063058537484995570.063058537484995570.063058537484995570.191816570929121550.191816570929121550.19181657092912155-0.12875803344412598-0.12875803344412598-0.1287580334441259800016.998840874218782
2013-03-11T00:00:00.000+000015.9961996545553512.289214546676674519.64558305529328715.99619965455535115.996199654555351-0.34100296963863064-0.34100296963863064-0.34100296963863064-0.2216619909946735-0.2216619909946735-0.2216619909946735-0.1193409786439571-0.1193409786439571-0.119340978643957100010.54144806941954
2013-03-12T00:00:00.000+000016.001896176108294.71795920592110821.62703871370901316.0018961761082916.00189617610829-0.1990742542931827-0.1990742542931827-0.1990742542931827-0.08884753072583874-0.08884753072583874-0.08884753072583874-0.11022672356734396-0.11022672356734396-0.1102267235673439600012.816330627572599
2013-03-13T00:00:00.000+000016.007592697661235.43245164862819722.20467670111377216.0075926976612316.00759269766123-0.16052181003844454-0.16052181003844454-0.16052181003844454-0.059031969203334006-0.059031969203334006-0.059031969203334006-0.10148984083511053-0.10148984083511053-0.1014898408351105300013.438024943474462
2013-03-14T00:00:00.000+000016.013289219214175.383767071013620522.64867750756175416.0132892192141716.01328921921417-0.1185821842560364-0.1185821842560364-0.1185821842560364-0.025389716700281756-0.025389716700281756-0.025389716700281756-0.09319246755575462-0.09319246755575462-0.0931924675557546200014.114398406476113
2013-03-15T00:00:00.000+000016.0189857407671076.98716694643266324.83045145748633316.01898574076710716.018985740767107-0.03371701567577938-0.03371701567577938-0.033717015675779380.0516661472129514160.0516661472129514160.051666147212951416-0.0853831628887308-0.0853831628887308-0.085383162888730800015.478873347435577
2013-03-16T00:00:00.000+000016.024682262320058.90005850374128625.2443665815997516.0246822623200516.024682262320050.073352314371385790.073352314371385790.073352314371385790.151448489482648720.151448489482648720.15144848948264872-0.07809617511126293-0.07809617511126293-0.0780961751112629300017.200129793327317
2013-03-17T00:00:00.000+000016.0303787838729878.97788969621410626.70669183973737816.03037878387298716.0303787838729870.120465441521993840.120465441521993840.120465441521993840.191816570929150.191816570929150.19181657092915-0.07135112940715617-0.07135112940715617-0.0713511294071561700017.96148544183705
2013-03-18T00:00:00.000+000016.036075305425933.636959548788045320.04095675314213716.0360753054259316.03607530542593-0.2868151261504682-0.2868151261504682-0.2868151261504682-0.22166199099449302-0.22166199099449302-0.22166199099449302-0.0651531351559752-0.0651531351559752-0.065153135155975200011.436686343741782
2013-03-19T00:00:00.000+000016.0417718269788664.7317053961697222.06004959386708816.04177182697886616.041771826978866-0.1483408300439927-0.1483408300439927-0.1483408300439927-0.08884753072608309-0.08884753072608309-0.08884753072608309-0.05949329931790963-0.05949329931790963-0.0594932993179096300013.662122078788485
2013-03-20T00:00:00.000+000016.0474683485318085.8706571434978322.2617108230550116.04746834853180816.047468348531808-0.1133815901384021-0.1133815901384021-0.1133815901384021-0.05903196920318045-0.05903196920318045-0.05903196920318045-0.05434962093522166-0.05434962093522166-0.0543496209352216600014.227980869479595
2013-03-21T00:00:00.000+000016.0531648700847466.17725463912365523.32138990552054716.05316487008474616.053164870084746-0.07507794783854334-0.07507794783854334-0.07507794783854334-0.02538971670043258-0.02538971670043258-0.02538971670043258-0.04968823113811075-0.04968823113811075-0.0496882311381107500014.847926195324987
2013-03-22T00:00:00.000+000016.0588613916376847.320806316060424.58078410462204416.05886139163768416.0588613916376840.00620121356226726460.00620121356226726460.00620121356226726460.0516661472126763650.0516661472126763650.051666147212676365-0.0454649336504091-0.0454649336504091-0.045464933650409100016.15844582069408
2013-03-23T00:00:00.000+000016.0645579131906269.19612695769365426.3407416382571716.06455791319062616.0645579131906260.109821496588109660.109821496588109660.109821496588109660.151448489482430170.151448489482430170.15144848948243017-0.0416269928943205-0.0416269928943205-0.041626992894320500017.82879170524358
2013-03-24T00:00:00.000+000016.0702544347435649.9379508222085927.45234623921872316.07025443474356416.0702544347435640.15370146032175980.15370146032175980.15370146032175980.191816570929343570.191816570929343570.19181657092934357-0.03811511060758378-0.03811511060758378-0.0381151106075837800018.540276009105884
2013-03-25T00:00:00.000+000016.0759509562965023.437047147422676520.23884974910164716.07595095629650216.075950956296502-0.25652751855726996-0.25652751855726996-0.25652751855726996-0.22166199099461026-0.22166199099461026-0.22166199099461026-0.03486552756265973-0.03486552756265973-0.0348655275626597300011.952027149029389
2013-03-26T00:00:00.000+000016.0816474778494445.61249747313240522.342340473895116.08164747784944416.081647477849444-0.1206597153442743-0.1206597153442743-0.1206597153442743-0.08884753072632748-0.08884753072632748-0.08884753072632748-0.031812184617946826-0.031812184617946826-0.03181218461794682600014.141240470905162
2013-03-27T00:00:00.000+000016.0873439994023855.67894896358349123.58406741743502316.08734399940238516.087343999402385-0.08792084617657114-0.08792084617657114-0.08792084617657114-0.05903196920349568-0.05903196920349568-0.05903196920349568-0.028888876973075454-0.028888876973075454-0.02888887697307545400014.672931102241343
2013-03-28T00:00:00.000+000016.0930405209553246.86624977738733424.2115592121167316.09304052095532416.093040520955324-0.05142105382327396-0.05142105382327396-0.05142105382327396-0.025389716700583403-0.025389716700583403-0.025389716700583403-0.026031337122690557-0.026031337122690557-0.02603133712269055700015.26551941814715
2013-03-29T00:00:00.000+000016.098737042508268.49651693910445625.003839839303316.0987370425082616.098737042508260.0284869616862893780.0284869616862893780.0284869616862893780.051666147212058320.051666147212058320.05166614721205832-0.02317918552576894-0.02317918552576894-0.0231791855257689400016.55734114783584
2013-03-30T00:00:00.000+000016.1044335640612039.57068125734973126.95070010239373216.10443356406120316.1044335640612030.131170796187006560.131170796187006560.131170796187006560.151448489482417240.151448489482417240.15144848948241724-0.02027769329541065-0.02027769329541065-0.0202776932954106500018.216864936799862
2013-03-31T00:00:00.000+000016.1101300856141410.3664598860963727.77318720595393516.1101300856141416.110130085614140.174537262849454760.174537262849454760.174537262849454760.191816570929195680.191816570929195680.19181657092919568-0.017279308079740922-0.017279308079740922-0.01727930807974092200018.921948094905886
2013-04-01T00:00:00.000+000016.115826607167083.954330220876113520.70953468181501516.1158266071670816.11582660716708-0.2358068935107037-0.2358068935107037-0.2358068935107037-0.22166199099472747-0.22166199099472747-0.22166199099472747-0.014144902515976235-0.014144902515976235-0.01414490251597623500012.315603598573867
2013-04-02T00:00:00.000+000016.121523128720025.457198666078272523.02040076237292316.1215231287200216.12152312872002-0.0996922446574312-0.0996922446574312-0.0996922446574312-0.08884753072599696-0.08884753072599696-0.08884753072599696-0.010844713931434238-0.010844713931434238-0.01084471393143423800014.514332300721229
2013-04-03T00:00:00.000+000016.127219650272966.43275486859175523.83596117652542616.1272196502729616.12721965027296-0.06639092323839184-0.06639092323839184-0.06639092323839184-0.0590319692030023-0.0590319692030023-0.0590319692030023-0.0073589540353895325-0.0073589540353895325-0.007358954035389532500015.056518648423003
2013-04-04T00:00:00.000+000016.1329161718258977.09285738979774724.54169568336538316.13291617182589716.132916171825897-0.02906779458410507-0.02906779458410507-0.02906779458410507-0.02538971670011468-0.02538971670011468-0.02538971670011468-0.003678077883990388-0.003678077883990388-0.00367807788399038800015.663967878500676
2013-04-05T00:00:00.000+000016.138612693378848.08862960822915725.71392938732423516.1386126933788416.138612693378840.05186343514032840.05186343514032840.05186343514032840.051666147212818040.051666147212818040.051666147212818040.000197287927510367970.000197287927510367970.0001972879275103679700016.975616586056773
2013-04-06T00:00:00.000+000016.1443092149317810.09002871285512126.90218232208508616.1443092149317816.144309214931780.155705236882418220.155705236882418220.155705236882418220.151448489482404250.151448489482404250.151448489482404250.0042567474000139750.0042567474000139750.00425674740001397500018.658062705545742
2013-04-07T00:00:00.000+000016.1500057364847210.963223394252528.182929413452316.1500057364847216.150005736484720.200297418094660950.200297418094660950.200297418094660950.191816570929047750.191816570929047750.191816570929047750.008480847165613190.008480847165613190.0084808471656131900019.384810187716575
2013-04-08T00:00:00.000+000016.1557022580376574.70454141691746120.7514004114399716.15570225803765716.155702258037657-0.2088199221887736-0.2088199221887736-0.2088199221887736-0.22166199099484468-0.22166199099484468-0.221661990994844680.012842068806071090.012842068806071090.0128420688060710900012.782069769609238
2013-04-09T00:00:00.000+000016.16139877959066.25836502954115323.6276852780298816.161398779590616.1613987795906-0.0715414670065356-0.0715414670065356-0.0715414670065356-0.08884753072594387-0.08884753072594387-0.088847530725943870.017306063719408250.017306063719408250.0173060637194082500015.005188602021052
2013-04-10T00:00:00.000+000016.1670953011435377.0450530692480923.9016297479295516.16709530114353716.167095301143537-0.0371988832273351-0.0371988832273351-0.0371988832273351-0.05903196920331756-0.05903196920331756-0.059031969203317560.0218330859759824640.0218330859759824640.02183308597598246400015.5656974109111

Showing the first 1000 rows.

How did our model perform? Here we can see the general and seasonal trends in our model presented as graphs:

trends_fig = model.plot_components(forecast_pd)
display(trends_fig)

And here, we can see how our actual and predicted data line up as well as a forecast for the future, though we will limit our graph to the last year of historical data just to keep it readable:

predict_fig = model.plot( forecast_pd, xlabel='date', ylabel='sales')

# adjust figure to display dates from last year + the 90 day forecast
xlim = predict_fig.axes[0].get_xlim()
new_xlim = ( xlim[1]-(180.0+365.0), xlim[1]-90.0)
predict_fig.axes[0].set_xlim(new_xlim)

display(predict_fig)

NOTE This visualization is a bit busy. Bartosz Mikulski provides an excellent breakdown of it that is well worth checking out. In a nutshell, the black dots represent our actuals with the darker blue line representing our predictions and the lighter blue band representing our (95%) uncertainty interval.

Visual inspection is useful, but a better way to evaulate the forecast is to calculate Mean Absolute Error, Mean Squared Error and Root Mean Squared Error values for the predicted relative to the actual values in our set: