Getting started with Time Series Forecasting with Prophet

Facebook prophet is simplest way to get started with time series analysis with python. Please refer to this post to know how to install prophet on Ubuntu.

We will have a look at official example with one complete program.

Here is the output on terminal

$ python3.6 01_fbprophet_getting_started.py 
*** Program Started ***
ds y
0 2007-12-10 9.590761
1 2007-12-11 8.519590
2 2007-12-12 8.183677
3 2007-12-13 8.072467
4 2007-12-14 7.893572
INFO:fbprophet:Disabling daily seasonality. Run prophet with daily_seasonality=True to override this.
Initial log joint probability = -19.4685
Iter log prob ||dx|| ||grad|| alpha alpha0 # evals Notes 
99 7975.37 0.00149529 224.247 1 1 128 
Iter log prob ||dx|| ||grad|| alpha alpha0 # evals Notes 
186 7992.27 5.72063e-05 157.088 5.678e-07 0.001 261 LS failed, Hessian reset 
199 7993.26 0.000312701 314.644 0.1004 1 277 
Iter log prob ||dx|| ||grad|| alpha alpha0 # evals Notes 
299 7997.05 0.0015387 170.701 1 1 408 
Iter log prob ||dx|| ||grad|| alpha alpha0 # evals Notes 
321 7998.61 0.00020668 308.573 1.22e-06 0.001 478 LS failed, Hessian reset 
369 8000.52 2.98767e-05 97.9518 2.746e-07 0.001 566 LS failed, Hessian reset 
399 8000.98 0.000153501 134.602 0.7945 0.7945 601 
Iter log prob ||dx|| ||grad|| alpha alpha0 # evals Notes 
457 8001.99 0.000276407 292.083 2.159e-06 0.001 718 LS failed, Hessian reset 
499 8002.58 0.000699641 197.602 1 1 770 
Iter log prob ||dx|| ||grad|| alpha alpha0 # evals Notes 
550 8003.07 5.79234e-05 181.032 3.403e-07 0.001 874 LS failed, Hessian reset 
599 8003.43 0.000218596 78.2273 0.7213 0.7213 928 
Iter log prob ||dx|| ||grad|| alpha alpha0 # evals Notes 
695 8004.08 3.66526e-05 116.76 2.994e-07 0.001 1095 LS failed, Hessian reset 
699 8004.11 0.000537041 111.615 1 1 1099 
Iter log prob ||dx|| ||grad|| alpha alpha0 # evals Notes 
788 8004.7 3.21305e-06 76.4964 4.987e-08 0.001 1259 LS failed, Hessian reset 
797 8004.7 6.1457e-07 61.1166 0.6741 0.6741 1270 
Optimization terminated normally: 
Convergence detected: relative gradient magnitude is below tolerance
type of m <class 'fbprophet.forecaster.Prophet'>
type of future <class 'pandas.core.frame.DataFrame'>
type of forecast <class 'pandas.core.frame.DataFrame'>
*** Program Completed ***

 

 

Let us try to run the same by using column name as date and value instead of ds and y. When I tried this, I got following error.

 

$ python3.6 01_fbprophet_getting_started.py 
*** Program Started ***
time value
0 2007-12-10 9.590761
1 2007-12-11 8.519590
2 2007-12-12 8.183677
3 2007-12-13 8.072467
4 2007-12-14 7.893572
Traceback (most recent call last):
File "01_fbprophet_getting_started.py", line 19, in <module>
m.fit(df)
File "/usr/local/lib/python3.6/site-packages/fbprophet/forecaster.py", line 1016, in fit
"Dataframe must have columns 'ds' and 'y' with the dates and "
ValueError: Dataframe must have columns 'ds' and 'y' with the dates and values respectively.

Daily Seasonality

You might have observed following message

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

To get rid of this message, add daily_seasonality=True prophet object. It will look like below.

m = Prophet(daily_seasonality=True)

 

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.