<jupyter_start><jupyter_text>Using the univariate fbProphet as the base prediction case - this will pick up the weekly and annual seasonality and the trend.<jupyter_code>m = Prophet()
gas_predict_src = gas_base['gas_demand'].reset_index()
gas_predict_src.columns = ['ds','y']
m.fit(gas_predict_src)
future = m.make_future_dataframe(periods=365)
future.tail()

forecast = m.predict(future)
forecast[['ds', 'yhat', 'yhat_lower', 'yhat_upper']].tail()
fig1 = m.plot(forecast)<jupyter_output><empty_output><jupyter_text>This shows clearly the drop over the weekend in gas demand - i.e. the weekly seasonality.<jupyter_code>fig2 = m.plot_components(forecast)
def mae_and_plot(forecast_df,actual_2018):
    p_predicted = forecast['yhat'].tail(365).values
    print(mean_absolute_error(p_predicted,actual_2018))
    pd.DataFrame({'Predicted':p_predicted,'Actual':actual_2018}).plot()
actual_2018 = gas_dat['gas_demand']['2018-01-01':'2018-12-31'].values
mae_and_plot(forecast,actual_2018)<jupyter_output>16.20326189643255<jupyter_text>Multiplicative Seasonality<jupyter_code># Python
m = Prophet(seasonality_mode='multiplicative')
m.fit(gas_predict_src)
forecast = m.predict(future)
fig = m.plot(forecast)

mae_and_plot(forecast,actual_2018)<jupyter_output>16.04948352947562<jupyter_text>Adding a predicted average of the temperature as a regressor<jupyter_code>temp_predict = gas_base.assign(avg_temp = (gas_base['s1_deg_c'] +gas_base['s2_deg_c'] )/2)['avg_temp'].reset_index()
temp_predict.columns = ['ds','y']

m_temp = Prophet()
m_temp.fit(temp_predict)
forecast_temp = m_temp.predict(future)
fig = m_temp.plot(forecast_temp)
gas_predict_regr = gas_predict_src.assign(avg_temp = temp_predict['y'])
m = Prophet(seasonality_mode='multiplicative')
m.add_regressor('avg_temp')
m.fit(gas_predict_regr)
future_regr = future.assign(avg_temp=forecast_temp['yhat'].values)

forecast = m.predict(future_regr)
fig = m.plot_components(forecast)<jupyter_output>/home/localusr/.local/share/virtualenvs/wip--aTygLyu/lib/python3.8/site-packages/fbprophet/plot.py:422: UserWarning: FixedFormatter should only be used together with FixedLocator
  ax.set_yticklabels(yticklabels)
/home/localusr/.local/share/virtualenvs/wip--aTygLyu/lib/python3.8/site-packages/fbprophet/plot.py:422: UserWarning: FixedFormatter should only be used together with FixedLocator
  ax.set_yticklabels(yticklabels)
/home/localusr/.local/share/virtualenvs/wip--aTygLyu/lib/python3.8/site-packages/fbprophet/plot.py:422: UserWarning: FixedFormatter should only be used together with FixedLocator
  ax.set_yticklabels(yticklabels)<jupyter_text>Adding the regressor of the predicted temperature wasn't helpful (note additive was 16.7)<jupyter_code>mae_and_plot(forecast,actual_2018)
pd.DataFrame({'Demand 2014':gas_dat['gas_demand']['2014-01-01':'2014-12-31'].values, 
'Demand 2015':gas_dat['gas_demand']['2015-01-01':'2015-12-31'].values, 
'Demand 2015':pd.concat([gas_dat['gas_demand']['2015-01-01':'2015-02-28'], 
    gas_dat['gas_demand']['2015-03-01':'2015-12-31']]).values,        
'Demand 2017':gas_dat['gas_demand']['2017-01-01':'2017-12-31'].values,    
'Demand 2018':gas_dat['gas_demand']['2018-01-01':'2018-12-31'].values}).plot()<jupyter_output><empty_output>
StarcoderdataJupyterStructuredCleanDedup