import pandas as pd
from prophet import Prophet
df = pd.read_csv('uk_cases_by_publish_date_06122021.csv')
df.head()
df = df[["date", "newCasesByPublishDate"]]
df = df.rename(columns={"newCasesByPublishDate": "y"})
df.info()
df["date"] = pd.to_datetime(df["date"], format = "%d/%m/%Y")
df = df.rename(columns={"date": "ds"})
#df = df.sort_values(by=["ds"], ascending=False)
#df['floor'] = 0
#df['cap'] = 100000
m = Prophet(yearly_seasonality=True, seasonality_mode='multiplicative')
m.add_country_holidays(country_name='UK')
m.fit(df)
future = m.make_future_dataframe(periods=365)
#future['floor'] = 0
#future['cap'] = 100000
future.tail()
forecast = m.predict(future)
forecast[['ds', 'yhat', 'yhat_lower', 'yhat_upper']].tail()
# Python
fig1 = m.plot(forecast)
# Python
fig2 = m.plot_components(forecast)
from prophet.plot import plot_plotly, plot_components_plotly
plot_plotly(m, forecast)
plot_components_plotly(m, forecast)
forecast = m.predict(future)
fig = m.plot_components(forecast)
forecast.head()
forecast.to_csv("UK Covid Cases Predictions.csv", index=False)
from sklearn.metrics import mean_absolute_percentage_error
forecast_pred = forecast[["ds", "yhat", "yhat_lower", "yhat_upper"]]
df.head()
df_combined = df.merge(forecast_pred, on="ds", how="left")
df_combined.head()
mean_absolute_percentage_error(df_combined["y"], df_combined["yhat"])
from sklearn.metrics import mean_absolute_error
mean_absolute_error(df_combined["y"], df_combined["yhat"])
df2021 = df_combined[(df_combined['ds'] > '2021-01-01') & (df_combined['ds'] < '2021-12-06')]
mean_absolute_percentage_error(df2021["y"], df2021["yhat"])
df2021.to_csv("2021_UK_COVID_finalpredictions.csv", index=False)