Reputation: 481
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:
Very frequently sampled (one data point every 15 minutes, as opposed to monthly data as the example uses) - but from what I've read, the Holt-Winters algorithm shouldn't have a problem with that. Perhaps that indicates a problem with the implementation?
Has multiple periodicities - there are daily peaks (i.e. every 96 data points) as well as a weekly cycle of weekend data being significantly lower than weekday data - for example weekdays can peak around 4000 but weekends peak at 1000 - but even when I only give it weekday data, I run into the negative-number problem.
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
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
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 seasonal pattern. Imagine a seasonal pattern, for example, where the last period of the year is always the largest value for the year. Then the trend will be biased upwards. Unfortunately, Bowerman, O’Connell and Koehler (2005) are not alone in recommending bad methods. I’ve seen similar, and worse, procedures recommended 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
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
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
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