Skip to content

Instantly share code, notes, and snippets.

@csetzkorn
Created July 22, 2017 06:58
Show Gist options
  • Save csetzkorn/9bb42a4a0dc26686d1a8991706acc11f to your computer and use it in GitHub Desktop.
Save csetzkorn/9bb42a4a0dc26686d1a8991706acc11f to your computer and use it in GitHub Desktop.
Followed this Facebook prophet tutorial https://www.digitalocean.com/community/tutorials/a-guide-to-time-series-forecasting-with-prophet-in-python-3 and adopted it slightly for PyCharm
import pandas as pd
from fbprophet import Prophet
import matplotlib.pyplot as plt
plt.style.use('fivethirtyeight')
df = pd.read_csv('D:/PyCharmProjects/Prophet/Data/AirPassengers.csv')
df['Month'] = pd.DatetimeIndex(df['Month'])
#Prophet also imposes the strict condition that the input columns be named ds (the time column) and y (the metric column)
df = df.rename(columns={'Month': 'ds',
'AirPassengers': 'y'})
print(df.head(5))
print(df.dtypes)
my_model = Prophet()
my_model.fit(df)
future_dates = my_model.make_future_dataframe(periods=36, freq='MS')
future_dates.tail()
forecast = my_model.predict(future_dates)
forecast[['ds', 'yhat', 'yhat_lower', 'yhat_upper']].tail()
my_model.plot(forecast,
uncertainty=True)
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment