Skip to content

Instantly share code, notes, and snippets.

@jiobu1
Created April 28, 2021 15:30
Show Gist options
  • Save jiobu1/6ae972dcc006b937b719d94c9779b0ab to your computer and use it in GitHub Desktop.
Save jiobu1/6ae972dcc006b937b719d94c9779b0ab to your computer and use it in GitHub Desktop.
prophet forecast model
def run_prophet(series):
model = Prophet(daily_seasonality=False,
weekly_seasonality=False,
yearly_seasonality=False)
model.fit(series)
forecast = model.make_future_dataframe(periods=10, freq='Y')
forecast = model.predict(forecast)
forecast = forecast[['ds', 'yhat', 'yhat_lower', 'yhat_upper']]
forecast['City,State'] = series['City,State'].iloc[0]
forecast = forecast[['City,State','ds', 'yhat', 'yhat_lower', 'yhat_upper']]
forecast['ds'] = pd.DatetimeIndex(forecast['ds']).year
forecast[['yhat', 'yhat_lower', 'yhat_upper']] = forecast[['yhat', 'yhat_lower', 'yhat_upper']].astype(float)
forecast[['yhat', 'yhat_lower', 'yhat_upper']] = forecast[['yhat', 'yhat_lower', 'yhat_upper']].apply(np.ceil)
return forecast
for i in range(len(series)):
f = run_prophet(series[i])
f.to_csv('csv/population_prediction.csv', mode='a', index='False')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment