from os import path
import requests
import numpy as np
import pandas as pd
from time_series_model_basics import moving_average, smoothing, metrics, optimizers
from statsmodels.tsa.api import ExponentialSmoothing, SimpleExpSmoothing, Holt
own_col = 'home_made_holt'
ts_col = 'sales'
nb_replicate = 10*2+1
datafile = '../data/superstore_sales.csv'
df = pd.read_csv(
datafile,
index_col='Order Date',
dtype={
'Row ID': str,
'Order ID': str,
},
parse_dates=['Order Date', 'Ship Date'],
)
df.columns = ['_'.join(x.lower().split(' ')) for x in df.columns]
df = pd.concat(nb_replicate * [df.reset_index()[[ts_col]]])
df.index = pd.date_range('1700-01-01', periods=len(df), freq='D')
df1 = df.copy()
df2 = df.copy()
smoothing_level = 0.1
smoothing_trend = 0.1
%%time
stats_holt = Holt(
df1[[ts_col]],
initialization_method="estimated",
).fit(
smoothing_level=smoothing_level,
smoothing_trend=smoothing_trend,
optimized=False,
)
sm_holt = 'sm_holt'
df1[sm_holt] = stats_holt.fittedvalues
%%time
_ = smoothing.DOUBLE(
[smoothing_level, smoothing_trend],
df=df2[[ts_col]],
ts_col=ts_col,
)