Skip to content

Instantly share code, notes, and snippets.

@marcosan93
Created September 23, 2021 18:32
Show Gist options
  • Save marcosan93/c820749031e12d1913297e67dfc33046 to your computer and use it in GitHub Desktop.
Save marcosan93/c820749031e12d1913297e67dfc33046 to your computer and use it in GitHub Desktop.
def fbpTrainPredict(df, forecast_period):
"""
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(
daily_seasonality=True,
yearly_seasonality=True,
weekly_seasonality=True
)
# Fitting to the prices
m.fit(df[['ds', 'y']])
# Future DF
future = m.make_future_dataframe(periods=forecast_period)
# 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