Skip to content

Instantly share code, notes, and snippets.

@marcosan93
Created January 13, 2022 22:57
Show Gist options
  • Select an option

  • Save marcosan93/ccd350391ea483cc3e2d806245d132ec to your computer and use it in GitHub Desktop.

Select an option

Save marcosan93/ccd350391ea483cc3e2d806245d132ec to your computer and use it in GitHub Desktop.
def fbpTrainPredict(df, forecast_hours):
"""
Uses FB Prophet and fits to a appropriately formatted DF. Makes a prediction N days into
the future based on given forecast period. Returns predicted values as a DF.
"""
# Setting up prophet
m = Prophet(
yearly_seasonality=False,
weekly_seasonality=False,
daily_seasonality=False
)
# Fitting to the prices
m.fit(df[['ds', 'y']])
# Future DF
future = m.make_future_dataframe(
periods=forecast_hours,
freq="H",
include_history=False
)
# Predicting values
forecast = m.predict(future)
# Returning a set of predicted values
return forecast[['ds', 'yhat', 'yhat_lower', 'yhat_upper']]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment