# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# # Exercise 05
#
# The result will be evaluated from a report in Jupyter, which must be found in a public GitHub repository.
# The project must be carried out in the groups assigned in class.
# Use clear and rigorous procedures.
# Due date: July 11, 2021, 11:59 pm, through Bloque Neón + (Upload repository link)
#
# ## Using the example_retail_sales dataset:
# - Standardize the dataset using np.log
# - Using prophet forescast the next 6 months of the sales logarithm
# - Predict the next 6 months of sales

# ### Solution
#
# <NAME> - 201924178
#
# <NAME> - 201527819
#
# <NAME>- 202020148
#
# <NAME> - 201113765
#
# <NAME> - 202022939
#
#
# github: https://github.com/zerodarkzone/AdvancedMethodsDataAnalysisClassGrupo4202119/

from prophet.plot import add_changepoints_to_plot
from prophet import Prophet
import pandas as pd
import numpy as np
# %matplotlib inline

# First, we read the data set using pandas and change de type of the 'ds' column to a datetime.

retail_sales = pd.read_csv('../datasets/example_retail_sales.csv')

retail_sales["ds"] = pd.to_datetime(retail_sales['ds'])

retail_sales.set_index("ds")['y'].plot()

# We apply the 'log' function to the variable to standardize the data and plot it.

retail_sales["y"] = np.log(retail_sales["y"])

retail_sales.set_index("ds")['y'].plot()

# At last, we fit the data to the prophet model.

m = Prophet()
m.fit(retail_sales)

# We make the prediction for the next 6 months

future = m.make_future_dataframe(periods=6, freq='M')
future.tail(6)

# We make the prediction

forecast = m.predict(future)
forecast[['ds', 'yhat', 'yhat_lower', 'yhat_upper']].tail()

# We plot the forecast of the next 6 months and plot the trend and the seasonality of the data

fig1 = m.plot(forecast)

m.plot_components(forecast);

# We can see that the data has an upwards trend and a yearly seasonality.



StarcoderdataJupyterScriptsDedupFiltered