<jupyter_start><jupyter_text>Another alternative for building time series models at scale.  Based on the research from facebook - [Prophet](https://research.fb.com/prophet-forecasting-at-scale/) - allows the user to quickly produce high quality forecasts with the ability to adjust multiple parameters.Initial code modeled after Digital Ocean's [tutorial](https://www.digitalocean.com/community/tutorials/a-guide-to-time-series-forecasting-with-prophet-in-python-3).<jupyter_code>!pip install fbprophet<jupyter_output>Requirement already satisfied: fbprophet in /usr/local/lib/python3.6/dist-packages (0.4.post2)
Requirement already satisfied: Cython>=0.22 in /usr/local/lib/python3.6/dist-packages (from fbprophet) (0.29.3)
Requirement already satisfied: pystan>=2.14 in /usr/local/lib/python3.6/dist-packages (from fbprophet) (2.18.1.0)
Requirement already satisfied: numpy>=1.10.0 in /usr/local/lib/python3.6/dist-packages (from fbprophet) (1.14.6)
Requirement already satisfied: pandas>=0.20.1 in /usr/local/lib/python3.6/dist-packages (from fbprophet) (0.22.0)
Requirement already satisfied: matplotlib>=2.0.0 in /usr/local/lib/python3.6/dist-packages (from fbprophet) (3.0.2)
Requirement already satisfied: lunardate>=0.1.5 in /usr/local/lib/python3.6/dist-packages (from fbprophet) (0.2.0)
Requirement already satisfied: convertdate>=2.1.2 in /usr/local/lib/python3.6/dist-packages (from fbprophet) (2.1.3)
Requirement already satisfied: holidays>=0.9.5 in /usr/local/lib/python3.6/dist-packages (from fbprophet[...]<jupyter_text><jupyter_code>import timeit
%matplotlib inline
import pandas as pd
from fbprophet import Prophet

import matplotlib.pyplot as plt
plt.style.use('fivethirtyeight')
# OBTAIN

df = pd.read_csv('https://raw.githubusercontent.com/2SUBDA/On-Campus/master/Dept1.csv', sep=',', error_bad_lines=False, encoding = "ISO-8859-1")
df.head()
# SCRUB
# Rename column for clarity

df = df.rename(index=str, columns={"Sales": "BevSales"})
df.head()
## SOME BASIC TIME DF MANIPULATION

# remove unwanted cols
# df = df.drop(columns = ['RegionID','City','State','Metro','CountyName','SizeRank'])
# convert zip code to col names
# df = df.set_index('ZipCode')
# transpose time series matrices
# df = df.T
# convert indices to date time
# df.index = pd.to_datetime(df.index)
# df.head()<jupyter_output><empty_output><jupyter_text>Prophet limits the naming convention of the input columns to be ds (date) and y (the value) - following code renames columns in the Data Frame - and makes data table [dfs] for each department with given format.<jupyter_code># SCRUB
# Rename columns for prophet

df = df.rename(index=str, columns={"BevSales": "y", "Date": "ds"})
df.head()
ax = df.set_index('ds').plot(figsize=(12, 8))
ax.set_ylabel('Weekly Sales of Beverages')
ax.set_xlabel('Date')

plt.show()
# MODEL
# Set the uncertainty interval to 95% (the Prophet default is 80%)

bev_model = Prophet(interval_width=0.95)
bev_model.fit(df)
future_dates = bev_model.make_future_dataframe(periods=13, freq='W')
future_dates.tail()
# MODEL

forecast = bev_model.predict(future_dates)
forecast[['ds', 'yhat', 'yhat_lower', 'yhat_upper']].tail()
# MODEL

bev_model.plot(forecast, uncertainty=True)
# INTERPRET

bev_model.plot_components(forecast)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1386682956627978, 'fraction_numerical': 0.028405620036652413, 'mean_word_length': 5.683673469387755, 'pattern_counts': {'":': 3, '<': 12, '<?xml version=': 0, '>': 20, 'https://': 3, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 1, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '455146', 'license': 'MIT', 'n_tokens_mistral': 1206, 'n_tokens_neox': 1137, 'n_words': 271, 'path': 'Time_Series_BeverageTimeForProphet.ipynb', 'repo_name': 'toraaglobal/CaseStudies', 'size': '3274'}