statsmodels: ExponentionalSmoothing forecasts bug?
Describe the bug
Some forecasts from ExponentialSmoothing(y_train, trend='add', damped=True) seem to be way off, see code and graph below where “replicated” comes from the code below and “original” is the forecast reported in the M4 competition, only part of the training series is shown. Data comes from the M4 competition.
- Seems to happen only on longer series (below one example, D703 series from the M4)
- Returned forecasts are constant and equal to
levelattribute. - With
damped=Falseseems to work as expected.
Code Sample, a copy-pastable example if possible
To run code, clone M4 methods Github repo and change paths accordingly.
# load packages
import pandas as pd
import numpy as np
import os
from statsmodels.tsa.holtwinters import ExponentialSmoothing
import matplotlib.pyplot as plt
# define paths
repodir = ".../m4-methods/" # repo root dir
datadir = os.path.join(repodir, "Dataset")
traindir = os.path.join(datadir, 'Train')
testdir = os.path.join(datadir, 'Test')
# select series from M4 dataset
dataset = 'Daily'
series_id = dataset[0] + str(703)
# load data
alltrain = pd.read_csv(os.path.join(traindir, f'{dataset}-train.csv'), index_col=0)
alltest = pd.read_csv(os.path.join(testdir, f'{dataset}-test.csv'), index_col=0)
y_train = alltrain.loc[series_id].dropna().reset_index(drop=True)
y_test = alltest.loc[series_id].dropna().reset_index(drop=True)
y_test.index = y_test.index + y_train.shape[0]
y_preds_original = pd.read_csv(os.path.join(repodir, 'Point Forecasts', 'submission-Damped.csv'), index_col=0)
y_pred_original = y_preds_original.loc[series_id].reset_index(drop=True).dropna()
y_pred_original.index = y_pred_original.index + y_train.shape[0]
# fit/forecast
m = ExponentialSmoothing(y_train, trend='add', damped=True)
mf = m.fit()
y_pred = mf.forecast(14)
# plot series/forecasts
fig, ax = plt.subplots(1)
y_train.iloc[-100:].plot(ax=ax, label='train')
y_test.plot(ax=ax, label='test')
y_pred.plot(ax=ax, label='replicated')
y_pred_original.plot(ax=ax, label='M4 forecasts');
plt.legend();
Expected Output
Forecasts closer to forecasts reported in M4 competition based on R forecast package or error/warning message.
Output of import statsmodels.api as sm; sm.show_versions()
INSTALLED VERSIONS
Python: 3.7.3.final.0 OS: Darwin 18.6.0 Darwin Kernel Version 18.6.0: Thu Apr 25 23:16:27 PDT 2019; root:xnu-4903.261.4~2/RELEASE_X86_64 x86_64 byteorder: little LC_ALL: None LANG: en_GB.UTF-8
Statsmodels
Installed: 0.9.0 (/Users/mloning/.conda/envs/sktime/lib/python3.7/site-packages/statsmodels)
Required Dependencies
cython: 0.29.7 (/Users/mloning/.conda/envs/sktime/lib/python3.7/site-packages/Cython) numpy: 1.16.4 (/Users/mloning/.conda/envs/sktime/lib/python3.7/site-packages/numpy) scipy: 1.2.1 (/Users/mloning/.conda/envs/sktime/lib/python3.7/site-packages/scipy) pandas: 0.24.2 (/Users/mloning/.conda/envs/sktime/lib/python3.7/site-packages/pandas) dateutil: 2.8.0 (/Users/mloning/.conda/envs/sktime/lib/python3.7/site-packages/dateutil) patsy: 0.5.1 (/Users/mloning/.conda/envs/sktime/lib/python3.7/site-packages/patsy)
Optional Dependencies
matplotlib: 3.0.3 (/Users/mloning/.conda/envs/sktime/lib/python3.7/site-packages/matplotlib) backend: module://ipykernel.pylab.backend_inline cvxopt: Not installed joblib: 0.12.5 (/Users/mloning/.conda/envs/sktime/lib/python3.7/site-packages/joblib)
Developer Tools
IPython: 7.4.0 (/Users/mloning/.conda/envs/sktime/lib/python3.7/site-packages/IPython) jinja2: 2.7.3 (/Users/mloning/.conda/envs/sktime/lib/python3.7/site-packages/jinja2) sphinx: 2.0.1 (/Users/mloning/.conda/envs/sktime/lib/python3.7/site-packages/sphinx) pygments: 2.3.1 (/Users/mloning/.conda/envs/sktime/lib/python3.7/site-packages/pygments) nose: Not installed pytest: 4.4.2 (/Users/mloning/.conda/envs/sktime/lib/python3.7/site-packages) virtualenv: Not installed
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 18 (17 by maintainers)
fixed in #6870