2
$\begingroup$

to avoid negative forecasts, in this post it was mentioned to increase each value with a small amount.

With the following example I am running into trouble doing this. This is not a forecast running in the negative, but after increasing with a small amount I get some extreme peaks in january, march and august and I don´t know why? Thanks.

library(forecast)
library(data.table)

# Raw data
data <- data.table(Quantity= c(1,0,3,0,0,0,0,2,0,0,0,1,0,1,0,0,0,0,0,0,0,0,1,0,0,1,1,1,1,0,0,0,0))
data <- ts(data, start = 2015, frequency = 12)
fit  <- ets(data)
forecast(fit)$mean
#constant forecast:
      Jan      Feb      Mar      Apr      May      Jun      Jul      Aug      Sep      Oct      Nov      Dec
2017                                                                                  0.394117 0.394117 0.394117
2018 0.394117 0.394117 0.394117 0.394117 0.394117 0.394117 0.394117 0.394117 0.394117 0.394117 0.394117 0.394117
2019 0.394117 0.394117 0.394117 0.394117 0.394117 0.394117 0.394117 0.394117 0.394117 





# cleaned zeros
data <- data.table(Quantity= c(1,0,3,0,0,0,0,2,0,0,0,1,0,1,0,0,0,0,0,0,0,0,1,0,0,1,1,1,1,0,0,0,0))
data[, Quantity:= Quantity+ 0.000001]
data <- ts(data, start = 2015, frequency = 12)
fit  <- ets(data)
forecast(fit)$mean
#peaks in january, march and august
            Jan              Feb              Mar              Apr              May              Jun              Jul              Aug              Sep              Oct              Nov              Dec
2017                                                                                                                                                            0.000001192611   0.310803479271   1.174457250582
2018 109.539589144456   0.981749264275   6.682781614938   0.228182592362   0.224480027454   0.036880656231   0.000002140478   4.214247916340   0.000001294715   0.000001865597   0.478752140756   1.783348443060
2019 164.121102890637   1.452669432838   9.773243119570   0.330057625443   0.321361260981   0.052285483147   0.000003006743   5.868476965626   0.000001788129                                                   
$\endgroup$
1
$\begingroup$
plot(forecast(fit,h=12))

forecast

ets() fitted an ETS(M,A,M) model. That is: a multiplicative error, additive trend and multiplicative seasonality model. Multiplicative errors and multiplicative seasonalities, especially fitted off very small baselines, can leverage up and explode. As you just saw.

When I'm done here, I'll be off to downvote Rob's post that gave you the idea of adding a small epsilon to your zeros.

You have so-called intermittent data. It's much better to use a dedicated forecasting method in such a case, rather than ETS. One such method is Croston's method.

Alternatively, if you can reasonably assume that the data generating process does not change over time, you can simply assume your data are IID and fit a Poisson distribution to your entire history. (Croston's method addresses a time changing DGP, but I wouldn't even be sure you can detect such dynamics with only three years of daily data.)

| cite | improve this answer | |
$\endgroup$
  • $\begingroup$ Thank you very much for the explanation! I thought ets automatically identifies smooth or irregular demand and choose the appropiate model. As I scale my code on multiple items, either smooth or irregular, in this case it is better to classify the items first according their demand structure. $\endgroup$ – Sven Nov 6 '17 at 16:27
  • 1
    $\begingroup$ Exactly. ets stands for "error, trend, seasonality", it doesn't (yet) do fully automated machine learning. There are tons of other forecasting situations where it would be inappropriate, such as Bass diffusion modeling, demographic forecasting or other use cases where other tools are more appropriate. $\endgroup$ – Stephan Kolassa Nov 6 '17 at 16:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.