0

premises

I have some data

data = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 130.67375459136835, 409.4142791551883, 587.7371441689623, 686.5900367309459, 692.0818640955006, 611.9657943067034, 436.22731864095533, 167.12777777777825, 1.0000000000000426, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]

From it I want to do some predictions using Holt's Linear model. Let's suppose I use statsmodels library:

from statsmodels.tsa.holtwinters import ExponentialSmoothing
model = ExponentialSmoothing(data, trend='add').fit()
plt.plot(model.predict(0, 24))

goal

Great! The predictions seem "pretty similar" to the given data. Now I'd want to predict it myself, using the summary data returned by the library:

print(model.summary())
def custom_holt_linear(data, alpha = 0.995, beta = 0.995, n=24):
    level = -97.8
    trend = 27.8

    predictions = []
    for i in range(1, len(data)):
        level_prev = level
        trend_prev = trend

        level = alpha * data[i] + (1 - alpha) * (level_prev + trend_prev)
        trend = beta * (level - level_prev) + (1 - beta) * trend_prev

    for i in range(n):
        prediction = level + i* trend
        predictions.append(prediction)

    return predictions

And see my results:

plt.plot(custom_holt_linear(data))

problem

Hmm.. my custom predictions seem far off. So, in general I fail to understand why. Is it incorrect to use the library's summary like I did? Or is my custom holt linear code wrong?

Thanks for the help!

0 Answers0