There's more...

We are also interested in some basic performance evaluation of the fitted model. Execute the following steps to visually inspect the predicted versus actual gold prices in 2005.

  1. Merge the test set with the forecasts:
selected_columns = ['ds', 'yhat_lower', 'yhat_upper', 'yhat']

df_pred = df_pred.loc[:, selected_columns].reset_index(drop=True)
df_test = df_test.merge(df_pred, on=['ds'], how='left')
df_test.ds = pd.to_datetime(df_test.ds)
df_test.set_index('ds', inplace=True)

We merged the test set with the prediction DataFrame. We used a left join, which returns all the rows from the left table (test set) and the matched rows from the right table (prediction DataFrame) while leaving the unmatched rows empty. This way, we also kept only the dates that were in the test set (Prophet created predictions for the next 365 days, including weekends and potential holidays).

  1. Plot the test values versus predictions:
fig, ax = plt.subplots(1, 1)

ax = sns.lineplot(data=df_test[['y', 'yhat_lower', 'yhat_upper',
'yhat']])
ax.fill_between(df_test.index,
df_test.yhat_lower,
df_test.yhat_upper,
alpha=0.3)
ax.set(title='Gold Price - actual vs. predicted',
xlabel='Date',
ylabel='Gold Price ($)')

Executing the code results in the following plot:

From the preceding plot, we can see that Prophet accurately (at least visually) predicted the price of gold over 2005. It was only over the first two months that the observed prices were outside of the confidence interval. 

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.190.176.78