<jupyter_start><jupyter_text><jupyter_code>!pip install pystan
!pip install fbprophet
# Import the required libraries and dependencies
import pandas as pd
from pathlib import Path
from fbprophet import Prophet
import datetime as dt
from datetime import datetime
%matplotlib inline
from google.colab import files
uploaded = files.upload()
df_orig = pd.read_csv('pivetal_latex_gloves.csv', parse_dates=True, infer_datetime_format=True)
df_orig.dropna(inplace=True)
item_list = df_orig['Item#'].unique()

print(df_orig.head())
print(item_list[:5])
finalized_list = []

for i in range(len(item_list)):
  try:
    item_num = item_list[i]

    df = df_orig.loc[df_orig['Item#'] == item_list[i]]

    df = df[['InvoiceDate', 'Qty']].copy()
    df['InvoiceDate'] = pd.to_datetime(df['InvoiceDate'])

    df_grouped = df.groupby(df.InvoiceDate).sum()
    df_grouped.reset_index(inplace=True)
    df_grouped.sort_values('InvoiceDate', inplace=True)
    df_grouped['t_qty'] = df_grouped['Qty'].cumsum()
    df = df_grouped[['InvoiceDate', 't_qty']].copy()

    df_sliced = df.loc[df['InvoiceDate'] < '2020-03-01']

    df_sliced.columns = ['ds', 'y']

    model = Prophet()
    model.fit(df_sliced)

    future_trends = model.make_future_dataframe(periods=173, freq='D')
    forecast_trends = model.predict(future_trends)

    forecast_trends = forecast_trends.set_index(["ds"])

    forecast = forecast_trends[["yhat", "yhat_lower", "yhat_upper"]].iloc[-173:,:]
    estimated_total = forecast['yhat'][-1] - forecast['yhat'][0]
    
    data = {"Item #": item_num, "Estimated 8 Month Qty":estimated_total}
    finalized_list.append(data)
  except:
    pass

final_df = pd.DataFrame(finalized_list)
final_df


df = df[['InvoiceDate', 'Qty']].copy()
df['InvoiceDate'] = pd.to_datetime(df['InvoiceDate'])
df.head()
df_grouped = df.groupby(df.InvoiceDate).sum()
df_grouped.reset_index(inplace=True)
df_grouped.sort_values('InvoiceDate', inplace=True)
df_grouped['t_qty'] = df_grouped['Qty'].cumsum()
df = df_grouped[['InvoiceDate', 't_qty']].copy()
df.tail()
df_sliced = df.loc[df['InvoiceDate'] < '2020-03-01']
df_sliced.tail()
df_sliced.columns = ['ds', 'y']
df_sliced
df_sliced.shape
model = Prophet()
model.fit(df_sliced)
future_trends = model.make_future_dataframe(periods=365, freq='D')
future_trends
forecast_trends = model.predict(future_trends)
forecast_trends
forecast_trends.tail()
model.plot(forecast_trends)
# Use the plot_components function to visualize the forecast results.
figures = model.plot_components(forecast_trends)
# At this point, it's useful to set the `datetime` index of the forecast data.
forecast_trends = forecast_trends.set_index(["ds"])
forecast_trends.head()
# From the `forecast_trends` DataFrame, use hvPlot to visualize
#  the yhat, yhat_lower, and yhat_upper columns over the last 10 days (24*10 = 240) 
forecast = forecast_trends[["yhat", "yhat_lower", "yhat_upper"]].iloc[-173:,:]
forecast.plot()
forecast = forecast_trends[["yhat", "yhat_lower", "yhat_upper"]].iloc[-173:,:]
estimated_total = forecast['yhat'][-1] - forecast['yhat'][0]
estimated_total<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15057915057915058, 'fraction_numerical': 0.014800514800514801, 'mean_word_length': 6.163594470046083, 'pattern_counts': {'":': 2, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, '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': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '504977', 'license': 'MIT', 'n_tokens_mistral': 1234, 'n_tokens_neox': 1160, 'n_words': 211, 'path': 'inventory_projection_fb_prophet.ipynb', 'repo_name': 'scottslusher/Alphabet-Soup', 'size': '3108'}