-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ExponentionalSmoothing forecasts bug? #5877
Comments
Any chance you could make the example more self-contained? For example, using simulated data that is like the data in the competition? |
I tried, but couldn't replicate the error with any of the simulated datasets that I tried, but it does happen on quite a few of the hourly and daily M4 datasets. |
Damping in general does not seem to work properly for me as it returns a constant line in many cases, but that may be intended, not sure: # generate data
rng = np.random.RandomState(1)
n = 100
y = np.zeros(n)
y[0] = 3
alpha = .75
beta = 0.01
for i in range(1, n):
y[i] = (alpha * y[i - 1]) + (beta * i) + rng.normal(loc=1, scale=0.5)
y = pd.Series(y)
# split into train/test
fh = 20 # forecast horizon
y_train = pd.Series(y[:-fh])
y_test = pd.Series(y[-fh:])
# fit/forecast
m = ExponentialSmoothing(y_train, trend='add', damped=False)
mf = m.fit()
y_undamped = mf.forecast(fh)
m = ExponentialSmoothing(y_train, trend='add', damped=True)
mf = m.fit()
y_damped = mf.forecast(fh)
# plot
fig, ax = plt.subplots(1)
y_train.iloc[-100:].plot(ax=ax, label='train')
y_test.plot(ax=ax, label='test')
y_damped.plot(ax=ax, label='damped')
y_undamped.plot(ax=ax, label='undamped')
plt.legend()
|
Fixed in #5893 |
Appears that this was not fixed by #5893 |
I can confirm this bug. Fitted values are fine but forecasts seem to be way off for any model that uses additive trend, although I haven't found the bug in the actual code yet. My guess is that something goes wrong using the trended(lvls, b) function when calculating the fitted values |
An update on this issue, although I haven't had time to fully look into it. I'm not sure that this is a "bug" in the sense of incorrect results from wrong code. Instead, what happens is that the trend smoothing parameter is getting fitted to be exactly zero. When there is no damping, this means that the trend is always fixed at the initial trend, which in e.g. the latest example here looks about right for the series as a whole (but in general wouldn't necessarily work out so well). When there is damping (even a relatively small amount), the initial trend gets damped to zero pretty quickly, and you get the flat line. But it seems this shouldn't happen (and doesn't happen in R), so more investigation is definitely necessary. |
According to @mloning sounds like you have to restrict the parameter to be high (>0.8) when included. |
This wasn't enough to make it work for me, since even relatively large damping parameters will damp the initial trend to zero relatively quickly. But I know that R has additional parameter restrictions that we don't use, e.g. on the trend smoothing parameter, and maybe in general this is a problem of parameter restrictions. I haven't had a chance to look into it yet though. |
I finally looked at the results from We do have different estimates because we don't restrict the damping parameter, which we estimate as about 0.2, while So I'm not sure there's a reproducible bug here. Clearly the graph in the first issue comment is concerning, but I think that we haven't been able to reproduce the problem? |
@ChadFulton Do you get a different forecast when you run the code on the selected series from the M4 datasets (using my code above)? |
Thanks for pointing this out. Yes, you're right, I get the same forecast and that's clearly a bug. |
I'm not quite sure what this bug is. It seems like a combination of the following:
|
Although something that I don't understand is going on with l-bfgs-b: reload(holtwinters)
mod = holtwinters.ExponentialSmoothing(endog, trend='add', damped=True)
res = mod.fit()
print(res.sse)
print('--------------')
print(res.mle_retvals) yields:
but the |
Solutions for this particular problem include:
Hard to know how this might generalize to other problems. |
I think that what might be best to implement, just to get a fix in, will be:
This is what the R forecast package does, at least for some of the parameters. If problems still persist, we can re-evaluate some of the other solutions. |
I think it comes from the seasonality adjustment in |
fixed in #6870 |
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.level
attribute.damped=False
seems to work as expected.Code Sample, a copy-pastable example if possible
To run code, clone M4 methods Github repo and change paths accordingly.
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
The text was updated successfully, but these errors were encountered: