import pandas as pd
from fbprophet import Prophet
import matplotlib. pyplot as plt
% matplotlib inline
df = pd. read_csv( './manning.csv' )
model = Prophet( )
model. fit( df)
future = model. make_future_dataframe( periods= 365 )
forecast = model. predict( future)
print ( forecast[ [ 'ds' , 'yhat' , 'yhat_lower' , 'yhat_upper' ] ] . tail( ) )
model. plot( forecast)
plt. show( )
forecast. tail( )
model. plot_components( forecast)
print ( forecast. columns)
df[ 'cap' ] = 8.5
m = Prophet( growth= 'logistic' )
m. fit( df)
future = m. make_future_dataframe( periods= 1826 )
future[ 'cap' ] = 8.5
fcst = m. predict( future)
fig = m. plot( fcst)
print ( future)
df[ 'y' ] = 10 - df[ 'y' ]
df[ 'cap' ] = 6
df[ 'floor' ] = 1.5
future[ 'cap' ] = 6
future[ 'floor' ] = 1.5
m = Prophet( growth= 'logistic' )
m. fit( df)
fcst = m. predict( future)
fig = m. plot( fcst)
from fbprophet. plot import add_changepoints_to_plot
fig = m. plot( forecast)
a = add_changepoints_to_plot( fig. gca( ) , m, forecast)
m = Prophet( changepoints= [ '2014-01-01' ] )
m. fit( df)
future = m. make_future_dataframe( periods= 365 )
forecast = m. predict( future)
m. plot( forecast) ;
playoffs = pd. DataFrame( {
'holiday' : 'playoff' ,
'ds' : pd. to_datetime( [ '2008-01-13' , '2009-01-03' , '2010-01-16' ,
'2010-01-24' , '2010-02-07' , '2011-01-08' ,
'2013-01-12' , '2014-01-12' , '2014-01-19' ,
'2014-02-02' , '2015-01-11' , '2016-01-17' ,
'2016-01-24' , '2016-02-07' ] ) ,
'lower_window' : 0 ,
'upper_window' : 1 ,
} )
superbowls = pd. DataFrame( {
'holiday' : 'superbowl' ,
'ds' : pd. to_datetime( [ '2010-02-07' , '2014-02-02' , '2016-02-07' ] ) ,
'lower_window' : 0 ,
'upper_window' : 1 ,
} )
holidays = pd. concat( ( playoffs, superbowls) )
m = Prophet( holidays= holidays)
m. fit( df)
future = m. make_future_dataframe( periods= 365 )
forecast = m. predict( future)
forecast[ ( forecast[ 'playoff' ] + forecast[ 'superbowl' ] ) . abs ( ) > 0 ] [ [ 'ds' , 'playoff' , 'superbowl' ] ] [ - 10 : ]
from fbprophet. plot import plot_forecast_component
m. plot_forecast_component( forecast, 'superbowl' )
model. plot_components( forecast)
print ( forecast. columns)