$$ \bar{x}t = \frac{1}{t} \bigg( \sum{\tau=1}^{t-1} x_\tau + x_t \bigg) $$
$$ \bar{y}t=\alpha y_t+(1-\alpha) \bar{y}{t-1} \text{ , where } 0 \le \alpha \le 1 $$
Non-trending, non-seasonal
Equations
Codes
from statsmodels.tsa.holtwinters. import SimpleExpSmoothing
df.index.freq = 'MS'
ses = SimpleExpSmoothing(df['Passengers'], initialization_method = 'legacy-heuristic')
alpha = 0.2
res = ses.fit(smoothing_level = alpha, optimized = False)
df['SES'] = res.predict(start = df.index[0], end = df.index[-1])
np.allclose(df['SES'], res.fittedvalues) # res.fittedvalues and res.predict(start = df.index[0], end = df.index[-1]) are same
df.plot()
N_test = 12
train = df.iloc[:-N_test]
test = df.iloc[-N_test:]
ses = SimpleExpSmoothing(train['Passengers'], initialization_method='legancy-heuristic')
res = ses.fit()
train_idx = df.index <= train.index[-1]
test_idx = df.index > train.index[-1]
df.loc[train_idx, 'SESfitted'] = res.fittedvalues
df.loc[test_idx, 'SESfitted] = res.forecast(N_test)
df[['Passengers', 'SESfitted']].plot()
res.params
Trending, but non-seasonal
Equations
Decide $\alpha,\beta$
$$ Error=\sum_{t=1}^T(y_t-\hat{y}_{t|t-1})^2 \\ \alpha,\beta=\text{arg } \underset{\alpha,\beta}{min} Error $$
Codes
from statsmodels.tsa.holtwinters.import Holt
holt = Holt(train['Passengers'], initialization_method='legacy-heuristic')
res_h = holt.fit() # no parameters, optimized itself
df.loc[train_idx, 'Holt'] = res_h.fittedvalues
df.loc[test_idx, 'Holt'] = res_h.forecast(N_test)
df[['Passengers', 'Holt']].plot()
Forecast:
$$ \hat{y}{t+h|t}=l_t+hb_t+s{t+h-mk} $$
Level:
$$ l_t=\alpha(y_t-s_{t-m})+(1-\alpha)(l_{t-1}+b_{t-1}) $$
Trend:
$$ b_t=\beta(l_t-l_{t-1})+(1-\beta)b_{t-1} $$
Seasonality:
$$ s_t=\gamma(y_t-l_{t-1}-b_{t-1})+(1-\gamma)s_{t-m} $$