pip3 install fbprophet
Linear Growth(+Change Point)
Non-Linear Growth(Logistic Growth)
from fbprophet import Prophet
%config InlineBackend.figure_format = 'retina'
import pandas as pd
df = pd.read_csv("./data/example_wp_log_peyton_manning.csv")
df.head(3)
ds | y | |
---|---|---|
0 | 2007-12-10 | 9.590761 |
1 | 2007-12-11 | 8.519590 |
2 | 2007-12-12 | 8.183677 |
m = Prophet(daily_seasonality=True)
Prophet?
m.fit(df)
INFO:fbprophet:Disabling daily seasonality. Run prophet with daily_seasonality=True to override this.
<fbprophet.forecaster.Prophet at 0x10d714c50>
future = m.make_future_dataframe(periods=365)
future.tail()
ds | |
---|---|
3265 | 2017-01-15 |
3266 | 2017-01-16 |
3267 | 2017-01-17 |
3268 | 2017-01-18 |
3269 | 2017-01-19 |
forecast = m.predict(future)
forecast.columns
Index(['ds', 'trend', 'yhat_lower', 'yhat_upper', 'trend_lower', 'trend_upper', 'additive_terms', 'additive_terms_lower', 'additive_terms_upper', 'weekly', 'weekly_lower', 'weekly_upper', 'yearly', 'yearly_lower', 'yearly_upper', 'multiplicative_terms', 'multiplicative_terms_lower', 'multiplicative_terms_upper', 'yhat'], dtype='object')
forecast.tail()
ds | trend | yhat_lower | yhat_upper | trend_lower | trend_upper | additive_terms | additive_terms_lower | additive_terms_upper | weekly | weekly_lower | weekly_upper | yearly | yearly_lower | yearly_upper | multiplicative_terms | multiplicative_terms_lower | multiplicative_terms_upper | yhat | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
3265 | 2017-01-15 | 7.188560 | 7.472689 | 8.921501 | 6.842721 | 7.584742 | 1.017937 | 1.017937 | 1.017937 | 0.048276 | 0.048276 | 0.048276 | 0.969662 | 0.969662 | 0.969662 | 0.0 | 0.0 | 0.0 | 8.206497 |
3266 | 2017-01-16 | 7.187532 | 7.835842 | 9.276909 | 6.839834 | 7.585662 | 1.343991 | 1.343991 | 1.343991 | 0.352295 | 0.352295 | 0.352295 | 0.991696 | 0.991696 | 0.991696 | 0.0 | 0.0 | 0.0 | 8.531523 |
3267 | 2017-01-17 | 7.186504 | 7.649349 | 9.053052 | 6.836947 | 7.587517 | 1.132426 | 1.132426 | 1.132426 | 0.119639 | 0.119639 | 0.119639 | 1.012787 | 1.012787 | 1.012787 | 0.0 | 0.0 | 0.0 | 8.318930 |
3268 | 2017-01-18 | 7.185477 | 7.409062 | 8.922735 | 6.834155 | 7.587927 | 0.966066 | 0.966066 | 0.966066 | -0.066664 | -0.066664 | -0.066664 | 1.032730 | 1.032730 | 1.032730 | 0.0 | 0.0 | 0.0 | 8.151543 |
3269 | 2017-01-19 | 7.184449 | 7.445664 | 8.928081 | 6.831499 | 7.588003 | 0.979028 | 0.979028 | 0.979028 | -0.072254 | -0.072254 | -0.072254 | 1.051282 | 1.051282 | 1.051282 | 0.0 | 0.0 | 0.0 | 8.163477 |
forecast[['ds', 'yhat', 'yhat_lower', 'yhat_upper']].tail()
ds | yhat | yhat_lower | yhat_upper | |
---|---|---|---|---|
3265 | 2017-01-15 | 8.206497 | 7.472689 | 8.921501 |
3266 | 2017-01-16 | 8.531523 | 7.835842 | 9.276909 |
3267 | 2017-01-17 | 8.318930 | 7.649349 | 9.053052 |
3268 | 2017-01-18 | 8.151543 | 7.409062 | 8.922735 |
3269 | 2017-01-19 | 8.163477 | 7.445664 | 8.928081 |
fig1 = m.plot(forecast)
fig2 = m.plot_components(forecast)
df['cap'] = 8.5
m = Prophet(growth='logistic')
m.fit(df)
INFO:fbprophet:Disabling daily seasonality. Run prophet with daily_seasonality=True to override this.
<fbprophet.forecaster.Prophet at 0x12b64a898>
future = m.make_future_dataframe(periods=1826)
future['cap'] = 8.5
fcst = m.predict(future)
fig = m.plot(fcst)
df['y'] = 10 - df['y']
df['cap'] = 6
df['floor'] = 1.5
future['cap'] = 6
future['floor'] = 1.5
m = Prophet(growth='logistic', daily_seasonality=True)
m.fit(df)
fcst = m.predict(future)
fig = m.plot(fcst)