import pandas as pd
from fbprophet import Prophet
df = pd.read_csv('https://raw.githubusercontent.com/danielcaraway/data/master/ca_train.csv')
df.head()
sm = df[['Date', 'ConfirmedCases']]
sm.columns = ['ds','y']
m = Prophet()
m.fit(sm)
future = m.make_future_dataframe(periods=365)
future.tail()
forecast = m.predict(future)
fig1 = m.plot(forecast)
def get_prof_preds_for(df, n):
m = Prophet()
m.fit(df)
future = m.make_future_dataframe(periods=n)
forecast = m.predict(future)
fig1 = m.plot(forecast)
get_prof_preds_for(sm, 60)
get_prof_preds_for(sm, 30)
get_prof_preds_for(sm, 10)
sm
get_prof_preds_for(sm[20:],10)
def get_prof_preds_for(df, n):
m = Prophet(daily_seasonality=True)
m.fit(df)
future = m.make_future_dataframe(periods=n)
forecast = m.predict(future)
fig1 = m.plot(forecast)
get_prof_preds_for(sm[20:],10)
get_prof_preds_for(sm[40:],10)
get_prof_preds_for(sm[40:],60)
get_prof_preds_for(sm[47:],30]
get_prof_preds_for(sm[47:],20)
sm = df[['Date', 'Fatalities']]
sm.columns = ['ds','y']
get_prof_preds_for(sm, 20)
sm
get_prof_preds_for(sm[47:], 20)
(using the mess we made above for fodder)
df.head()
cc = df[['Date', 'ConfirmedCases']] # cc = Confirmed Cases
fc = df[['Date', 'Fatalities']] # fc = Fatal Cases
def get_prof_preds_for(df, n):
df.columns = ['ds', 'y']
m = Prophet()
m.fit(df)
future = m.make_future_dataframe(periods=n)
forecast = m.predict(future)
fig1 = m.plot(forecast)
return forecast
pred_cc_1 = get_prof_preds_for(cc, 40)
pred_fc_1 = get_prof_preds_for(fc, 40)
pred_cc_1.tail()['yhat']
pred_fc_1.tail()['trend']
pred_fc_1.tail()
pred_cc_2 = get_prof_preds_for(cc[40:], 40)
pred_fc_2 = get_prof_preds_for(fc[40:], 40)
pred_cc_2.tail()['yhat']
pred_fc_2.tail()['yhat']
pred_fc_2.tail()
pred_cc_3 = get_prof_preds_for(cc[47:], 40)
pred_fc_3 = get_prof_preds_for(fc[47:], 40)
pred_cc_3.tail()
pred_fc_3.tail()
pred_cc_1_sm = pred_cc_1[['ds','yhat']]
pred_cc_2_sm = pred_cc_2[['ds','yhat']]
pred_cc_3_sm = pred_cc_3[['ds','yhat']]
# lol pandas says this way
# pred_cc_1_sm.merge(pred_cc_2_sm, left_on='ds')
# stackoverflow says this way (better)
cc_df = pd.merge(pred_cc_1_sm, pred_cc_2_sm, how='left', on='ds', suffixes=('_v1', '_v2'))
cc_df = pd.merge(cc_df, pred_cc_3_sm, how='left', on='ds')
cc_df.columns = ['ds','yhat_v1', 'yhat_v2', 'yhat_v3']
cc_df
pred_fc_1_sm = pred_fc_1[['ds','yhat']]
pred_fc_2_sm = pred_fc_2[['ds','yhat']]
pred_fc_3_sm = pred_fc_3[['ds','yhat']]
fc_df = pd.merge(pred_fc_1_sm, pred_fc_2_sm, how='left', on='ds', suffixes=('_v1', '_v2'))
fc_df = pd.merge(fc_df, pred_fc_3_sm, how='left', on='ds')
fc_df.columns = ['ds','yhat_v1', 'yhat_v2', 'yhat_v3']
fc_df