In [26]:
%matplotlib inline

import pandas as pd
import numpy as np

from fbprophet import Prophet

In [27]:
df = pd.read_csv('analytics-2017.pycon.ca-audience-overview_20170123-20170526.csv',
                 sep='\t', parse_dates=['Date'])
df.tail()


Out[27]:
Date Sessions
119 2017-05-22 16
120 2017-05-23 31
121 2017-05-24 31
122 2017-05-25 25
123 2017-05-26 17

In [28]:
df.set_index('Date').plot()


Out[28]:
<matplotlib.axes._subplots.AxesSubplot at 0x10abd4278>

In [29]:
df['Sessions'] = np.log(df['Sessions'])
df.set_index('Date').plot()


Out[29]:
<matplotlib.axes._subplots.AxesSubplot at 0x10b01feb8>

In [30]:
df.columns = ['ds', 'y']
df.head()


Out[30]:
ds y
0 2017-01-23 3.218876
1 2017-01-24 3.526361
2 2017-01-25 3.218876
3 2017-01-26 2.995732
4 2017-01-27 2.995732

In [31]:
prophet = Prophet()
prophet.fit(df)


Out[31]:
<fbprophet.forecaster.Prophet at 0x10ac89a20>

In [32]:
future = prophet.make_future_dataframe(periods=365)

In [33]:
forecast = prophet.predict(future)

In [34]:
forecast[['ds', 'yhat', 'yhat_lower', 'yhat_upper']].tail()


Out[34]:
ds yhat yhat_lower yhat_upper
484 2018-05-22 2.056819 1.587713 2.512842
485 2018-05-23 2.126686 1.630847 2.562205
486 2018-05-24 1.796638 1.316910 2.316290
487 2018-05-25 1.842713 1.326227 2.302523
488 2018-05-26 1.378937 0.870114 1.867801

In [35]:
np.exp(forecast[['yhat', 'yhat_lower', 'yhat_upper']].tail())


Out[35]:
yhat yhat_lower yhat_upper
484 7.821049 4.892546 12.339945
485 8.387030 5.108202 12.964368
486 6.029342 3.731872 10.137993
487 6.313646 3.766805 9.999379
488 3.970677 2.387183 6.474047

In [36]:
prophet.plot(forecast)


Out[36]:

In [37]:
prophet.plot_components(forecast)


Out[37]:

In [ ]: