Skip to content

Instantly share code, notes, and snippets.

@tomonori-masui
Created July 4, 2021 04:43
Show Gist options
  • Save tomonori-masui/be7b5012884c7c6cd527170b48bedd9f to your computer and use it in GitHub Desktop.
Save tomonori-masui/be7b5012884c7c6cd527170b48bedd9f to your computer and use it in GitHub Desktop.
from fbprophet import Prophet
al_train_pp = al_train.to_timestamp(freq="M").reset_index()
# Prophet requires specific column names: ds and y
al_train_pp.columns = ["ds", "y"]
# turning on only yearly seasonality as this is monthly data.
# As the seasonality effects varies across years, we need multiplicative seasonality mode
m = Prophet(
seasonality_mode="multiplicative",
yearly_seasonality=True,
weekly_seasonality=False,
daily_seasonality=False,
)
m.fit(al_train_pp)
future = m.make_future_dataframe(periods=test_len, freq="M")
forecast = m.predict(future)
forecast = forecast.iloc[-test_len:]
forecast.rename(columns={"yhat_lower": "lower", "yhat_upper": "upper"}, inplace=True)
al_pph_mae, al_pph_mape = plot_forecast(
al_train, al_test, forecast["yhat"], forecast[["lower", "upper"]]
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment