In [16]:
import pandas as pd
import pyflux as pf
import matplotlib.pyplot as plt
from fbprophet import Prophet
    
%matplotlib inline
plt.rcParams['figure.figsize']=(20,10)
plt.style.use('ggplot')

Load the data

For this work, we're going to use the same retail sales data that we've used before. It can be found in the examples directory of this repository.


In [11]:
sales_df = pd.read_csv('../examples/retail_sales.csv', index_col='date', parse_dates=True)

In [12]:
sales_df.head()


Out[12]:
sales
date
2009-10-01 338630
2009-11-01 339386
2009-12-01 400264
2010-01-01 314640
2010-02-01 311022

Like all good modeling projects, we need to take a look at the data to get an idea of what it looks like.


In [15]:
sales_df.plot()


Out[15]:
<matplotlib.axes._subplots.AxesSubplot at 0x7f9ac123add0>

It's pretty clear from this data that we are looking at a trending dataset with some seasonality. This is actually a pretty good datset for prophet since the additive model and prophet's implemention does well with this type of data.

With that in mind, let's take look at what prophet does from a modeling standpoint to compare with the dynamic linear regression model. For more details on this, you can take a look at my blog post titled Forecasting Time Series data with Prophet – Part 4 (http://pythondata.com/forecasting-time-series-data-prophet-part-4/)


In [17]:
# Prep data for prophet and run prophet
df = sales_df.reset_index()
df=df.rename(columns={'date':'ds', 'sales':'y'})

model = Prophet(weekly_seasonality=True)
model.fit(df);
future = model.make_future_dataframe(periods=24, freq = 'm')
future.tail()
forecast = model.predict(future)
model.plot(forecast);


INFO:fbprophet.forecaster:Disabling daily seasonality. Run prophet with daily_seasonality=True to override this.

With our prophet model ready for comparison, let's build a model with pyflux's dynamic linear regresion model.


In [21]:
sales_df['revenue'] = sales_df.sales

In [22]:
model = pf.DynReg('revenue ~ sales', data=sales_df)

In [23]:
model.plot_fit(figsize=(15,15))


---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-23-a1c5381353d9> in <module>()
----> 1 model.plot_fit(figsize=(15,15))

/vagrant/pythondata/env/local/lib/python2.7/site-packages/pyflux/ssm/dynlin.pyc in plot_fit(self, intervals, **kwargs)
    300         """
    301         import matplotlib.pyplot as plt
--> 302         import seaborn as sns
    303 
    304         figsize = kwargs.get('figsize',(10,7))

ImportError: No module named seaborn

In [ ]: