1

This code:

import numpy as np
from statsmodels.tsa.api import ExponentialSmoothing
time_series = np.array([1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4])
print(ExponentialSmoothing(time_series, seasonal_periods=4, trend=None, seasonal="add").fit().forecast(4))    # [1. 2. 3. 4.]

runs without warnings and correctly prints [1. 2. 3. 4.] on my computer (Anaconda Navigator 1.9.12 with Visual Studio Code 1.45.1, running python 3.7.6, numpy 1.18.1, statsmodels 0.11.0).

However on my colleague's computer (Visual Studio Code running Python 3.8, numpy 1.18.4, statsmodels 0.11.0) the same code triggers the following warnings before correctly printing [1. 2. 3. 4.]:

...\statsmodels\tsa\holtwinters.py:725: RuntimeWarning: invalid value encountered in less_equal loc = initial_p <= lb

...\statsmodels\tsa\holtwinters.py:731: RuntimeWarning: invalid value encountered in greater_equal loc = initial_p >= ub

...\statsmodels\tsa\holtwinters.py:956: RuntimeWarning: divide by zero encountered in log aic = self.nobs * np.log(sse / self.nobs) + k * 2

...\statsmodels\tsa\holtwinters.py:962: RuntimeWarning: divide by zero encountered in log bic = self.nobs * np.log(sse / self.nobs) + k * np.log(self.nobs)

How can we fix things so that my colleague doesn't get these RuntimeWarnings, please? Or should we not worry about them? Many thanks.

UPDATE: I think I have found the answer. My test data was too perfect and the warnings were caused by that. Introducing jitter into the data eliminates the warnings. Either way I think, on the basis of this, that we can ignore the warnings anyway:

import numpy as np
from statsmodels.tsa.api import ExponentialSmoothing
time_series = np.array([1.2, 1.8, 3.2, 3.8, 1, 2, 3, 4, 1.1, 1.9, 3.1, 3.9, 1, 2, 3, 4])
print(ExponentialSmoothing(time_series, seasonal_periods=4, trend=None, seasonal="add").fit().forecast(4))
# [1.07500096 1.92499933 3.07500112 3.92499949]

ANOTHER UPDATE: Nope, that wasn't it. On my computer I still get no warnings, but my colleague gets

...\statsmodels\tsa\holtwinters.py:725: RuntimeWarning: invalid value encountered in less_equal loc = initial_p <= lb

...\statsmodels\tsa\holtwinters.py:731: RuntimeWarning: invalid value encountered in greater_equal loc = initial_p >= ub

Community
  • 1
  • 1
capnbobski
  • 11
  • 3

1 Answers1

0

Take a look at the function in the library. This will give you an answer.

    def _enforce_bounds(self, p, sel, lb, ub):
        initial_p = p[sel]

        # Ensure strictly inbounds
        loc = initial_p <= lb
        upper = ub[loc].copy()
        upper[~np.isfinite(upper)] = 100.0
        eps = 1e-4
        initial_p[loc] = lb[loc] + eps * (upper - lb[loc])

        loc = initial_p >= ub
        lower = lb[loc].copy()
        lower[~np.isfinite(lower)] = -100.0
        eps = 1e-4
        initial_p[loc] = ub[loc] - eps * (ub[loc] - lower)

        return initial_p

It seems that your code is not using the right bounds to run ExponentialSmoothing()

  • Hey John, could you be a bit more specific? How exactly this function relates to the OP's question? Which bounds are not right, why, and how to fix them? Also, maybe it would be a good idea to add a link to the function's source code? Your answer is more like a tip at the moment, not a complete answer :) – natka_m Jan 12 '21 at 16:52