Wern
Wern

Reputation: 481

Using Holt-Winters for forecasting in Python

I've been trying to use this implementation of the Holt-Winters algorithm for time series forecasting in Python but have run into a roadblock... basically, for some series of (positive) inputs, it sometimes forecasts negative numbers, which should clearly not be the case. Even if the forecasts are not negative, they are sometimes wildly inaccurate - orders of magnitude higher/lower than they should be. Giving the algorithm more periods of data to work with does not appear to help, and in fact often makes the forecast worse.

The data I'm using has the following characteristics, which might be problems:

Is there something I'm missing with either the implementation or my usage of the Holt-Winters algorithm in general? I'm not a statistician so I'm using the 'default' values of alpha, beta, and gamma indicated in the link above - is that likely to be the problem, and is there a better way to calculate those values?

Or ... is there a better algorithm to use here than Holt-Winters? Ultimately I just want to create sensible forecasts from historical data here. I've tried single- and double-exponential smoothing but (as far as I understand) neither support periodicity in data.

Any help/input would be greatly appreciated!

Upvotes: 24

Views: 17045

Answers (5)

Jefferson
Jefferson

Reputation: 529

Is is important to analyze time series properties before choosing an adequate forecast method.

1 - Before applying Holt-Winters, it might be important to check whether your time series is stationary and, if it is not, differentiate it to achieve this property, which helps with accuracy.

2 - Data can change periodically over time, and what seems to be trend might actually be part of a big seasonal period. If that's your case (and it is), maybe you should apply Holt-Winters twice, once for each seasonal period, as it can't handle multiple periodicities, and then analyze what fits better in your scenario.

3 - Experimenting different smoothing parameters (alpha, beta and gamma) may be important. The bigger they are, more important the few last observations and last computed components become. Try to find an adaptive Holt-Winters implementation, which adapts these parameters automatically, to see what happens.

I recommend you to use the R language, which contains an adaptive and easy to use Holt-Winters implementation, provided through the forecast package, so you can easily experiment different configurations.

Upvotes: 0

user1883737
user1883737

Reputation: 263

I think the problem with this method is how they calculate the initial values. They seems to be using a linear model when:

This is a very poor method that should not be used as the trend will be biased by the sea­sonal pat­tern. Imag­ine a sea­sonal pat­tern, for exam­ple, where the last period of the year is always the largest value for the year. Then the trend will be biased upwards. Unfor­tu­nately, Bow­er­man, O’Connell and Koehler (2005) are not alone in rec­om­mend­ing bad meth­ods. I’ve seen sim­i­lar, and worse, pro­ce­dures rec­om­mended in other books. [1]

a better method si decomposinf the timeseries in trend and seasonality [1]

[1] http://robjhyndman.com/hyndsight/hw-initialization/

Upvotes: 0

Michael
Michael

Reputation: 7736

Firstable, if you're unsure about your specific implementation of the algorithm, I recommend that you create some testcase for that. Take another implementation, maybe matlab, whatever, anything that you know it works. Generate some inputs, feed it to the reference and to your implementation, and it should be identical. I have translated and verified some algorithms from matlab that way. scipy.io.loadmat is great for that.

About your usage of the algorithm: You're talking about periodicities in days and weeks, and you feed data on a minutes timescale. I don't know if this specific algorithm handles that well, but in any case I'd suggest, to try some lowpass filtering and then feeding it into the algorithm hourly, or even slower. Nearly 700 timesteps for one period could be just too much to recognize. The data that you feed in should also contain a minimum two complete periods of your timeseries. If your algorithm supports periodicity, you also have to provide it with data in an appropriate way, so it can actually see the periodicity. The fact, that you get these extrem values could be a hint, that the algorithm only has date for a steady trend in one direction.

Maybe you also want to separate your forcasts to have one optimized for weekly prediction, and the other one intraday, and you combine them in the end again.

Upvotes: 1

user1202733
user1202733

Reputation: 623

The fact that you observe there are periodicities in your data, means that you should also try to use a model that can express such characteristics.

Holt-Winters is a simple smoothing model which can not express this.

The classic approach is to look at the ARMA model (Autoregressive Moving Average) , and its natural extension the SARIMA (Seasonally Adjusted...) model.

Bottom Line : This is really a statistics question. One of the best texts on the subject is Econometrics by Maddala.

Upvotes: -4

Mu Mind
Mu Mind

Reputation: 11194

I tried generating random data until I got interesting results. Here I fed in all positive numbers and got negative forecasts:

y = [0.92, 0.78, 0.92, 0.61, 0.47, 0.4, 0.59, 0.13, 0.27, 0.31, 0.24, 0.01]
holtwinters(y, 0.2, 0.1, 0.05, 4)

...
forecast: -0.104857182966
forecast: -0.197407475203
forecast: -0.463988558577
forecast: -0.258023593197

but note that the forecast fits the negative slope of the data.

This might be the orders of magnitude you were talking about:

y = [0.1, 0.68, 0.15, 0.08, 0.94, 0.58, 0.35, 0.38, 0.7, 0.74, 0.93, 0.87]
holtwinters(y, 0.2, 0.1, 0.05, 4)

...
forecast: 1.93777559066
forecast: 3.11109138055
forecast: 0.910967977635
forecast: 0.684668348397

But I'm not sure how you'd deem it wildly inaccurate or judge that it "should be" lower.


Whenever you're extrapolating data, you're going to have somewhat surprising results. Are you concerned more that the implementation might be incorrect or that the output doesn't have good properties for your specific usage?

Upvotes: 2

Related Questions