Skip to content

Instantly share code, notes, and snippets.

@conquistadorjd
Last active March 21, 2019 03:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save conquistadorjd/189621647ff74253166186f333a2c59c to your computer and use it in GitHub Desktop.
Save conquistadorjd/189621647ff74253166186f333a2c59c to your computer and use it in GitHub Desktop.
fbprophet
################################################################################################
# name: 01_fbprophet_getting_started.py
# desc: Official tutorial
# date: NA
# Author: NA
################################################################################################
import pandas as pd
from fbprophet import Prophet
print('*** Program Started ***')
### Impoting data as pandas dataframe
df = pd.read_csv('example_wp_log_peyton_manning.csv')
print(df.head())
### Initiating new object Prophet & initiating fit method and passing input dataframe. Fitting should take 1-5 seconds
m = Prophet()
m.fit(df)
print("type of m" , type(m))
### Extending data to few future dates
future = m.make_future_dataframe(periods=365)
print("type of future" , type(future))
### The predict method will assign each row in future a predicted value which it names yhat
forecast = m.predict(future)
print("type of forecast" , type(future))
# print(forecast[['ds', 'yhat', 'yhat_lower', 'yhat_upper']].tail())
### Plotting forecast
fig1 = m.plot(forecast)
# fig1.show()
fig1.savefig('01_fbprophet_getting_started-01.png')
### Plotting forecast components
fig2 = m.plot_components(forecast)
fig2.savefig('01_fbprophet_getting_started-02.png')
### Saving output excel
forecast.to_csv('example_wp_log_peyton_manning_output.csv', sep=',')
print('*** Program Completed ***')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment