Recently I got interested in analyzing trends in time series and explored few forecasting techniques.
A good read to start are :
Next step after visualizing, is to find trends and forecast. Before forecasting future data points, I suggest forecast over current data set and try to get close fit as possible. Some of my observations from studying all the 3 smoothing methods are :
1) Single exponential should be used to when there are hardly any trends. Forecast value is almost equivalent to last data point. Only gain you get out of this method is to gain insight to alpha value by minimizing Mean Squared Error.
2) Double exponential method gives you better forecast values when there is some trend...say continuously going up or down. Forecasts are much better than single exponential. Playing with gamma value is fun.
3) Triple exponential method is good with trend plus season. By carefully iterating over period,alpha,beta,gamma, and each time minimizing MSE, one can get pretty close forecasts.
Here are my codes used :
PS: Let me know if code has problems
A good read to start are :
- http://www.itl.nist.gov/div898/handbook/pmc/section4/pmc4.htm
- http://en.wikipedia.org/wiki/Moving_average
- http://en.wikipedia.org/wiki/Exponential_smoothing
Next step after visualizing, is to find trends and forecast. Before forecasting future data points, I suggest forecast over current data set and try to get close fit as possible. Some of my observations from studying all the 3 smoothing methods are :
1) Single exponential should be used to when there are hardly any trends. Forecast value is almost equivalent to last data point. Only gain you get out of this method is to gain insight to alpha value by minimizing Mean Squared Error.
2) Double exponential method gives you better forecast values when there is some trend...say continuously going up or down. Forecasts are much better than single exponential. Playing with gamma value is fun.
3) Triple exponential method is good with trend plus season. By carefully iterating over period,alpha,beta,gamma, and each time minimizing MSE, one can get pretty close forecasts.
Here are my codes used :
/** * http://www.itl.nist.gov/div898/handbook/pmc/section4/pmc431.htm * http://www.itl.nist.gov/div898/handbook/pmc/section4/pmc432.htm * @param data - input data * @param alpha - good value between 0.1-0.9 * @param numForecasts - ahead forecasts * @return */ public static double[] singleExponentialForecast(double[] data, double alpha, int numForecasts) { double[] y = new double[data.length + numForecasts]; y[0] = 0; y[1] = data[0]; int i = 2; for (i = 2; i < data.length; i++) { y[i] = alpha * data[i - 1] + (1 - alpha) * y[i - 1]; } for (int j = 0; j < numForecasts; j++, i++) { y[i] = alpha * data[data.length - 1] + (1 - alpha) * y[i - 1]; } return y; } /** * http://www.itl.nist.gov/div898/handbook/pmc/section4/pmc433.htm * http://www.itl.nist.gov/div898/handbook/pmc/section4/pmc434.htm * @param data * @param alpha * @param gamma * @param initializationMethod * @param numForecasts * @return */ public static double[] doubleExponentialForecast(double[] data, double alpha, double gamma, int initializationMethod, int numForecasts) { double[] y = new double[data.length + numForecasts]; double[] s = new double[data.length]; double[] b = new double[data.length]; s[0] = y[0] = data[0]; if(initializationMethod==0) { b[0] = data[1]-data[0]; } else if(initializationMethod==1 && data.length>4) { b[0] = (data[3] - data[0]) / 3; } else if(initializationMethod==2) { b[0] = (data[data.length - 1] - data[0])/(data.length - 1); } int i = 1; y[1] = s[0] + b[0]; for (i = 1; i < data.length; i++) { s[i] = alpha * data[i] + (1 - alpha) * (s[i - 1]+b[i - 1]); b[i] = gamma * (s[i] - s[i - 1]) + (1-gamma) * b[i-1]; y[i+1] = s[i] + b[i]; } for (int j = 0; j < numForecasts ; j++, i++) { y[i] = s[data.length-1] + (j+1) * b[data.length-1]; } return y; } public static double TSAError(double[] data, double[] forecast) { double mad = 0.0; double mse = 0.0; double diff = 0.0; for (int i = 0; i < data.length; i++) { diff = data[i] - forecast[i]; mad += Math.abs(diff); mse += Math.pow(Math.abs(diff), 2.0); } return mse/data.length; }Triple Exponential code can be found at http://n-chandra.blogspot.in/2011/04/holt-winters-triple-exponential.html
PS: Let me know if code has problems
i have one doubt ....... in doubeexponential method for what purpose this initializationMethod you took and what is this TSAError method ?
ReplyDeletewhat name I have to use to save?
ReplyDeleteexponentialsmoothing.java or other else?
You made such an interesting piece to read, giving every subject enlightenment for us to gain knowledge. Thanks for sharing the such information with us
ReplyDeleteData Science training in chennai
Data Science training in OMR
Data Science training in chennai
Data Science Training in Chennai
Data Science training in Chennai
Data Science training in anna nagar
This comment has been removed by the author.
ReplyDeleteHi,
ReplyDeleteIs there any implementation to calculate the optimum value of alpha and beta for Double Exponential Smoothing ?
Can you share for me this file *.zip?
ReplyDeletethanks so much!
pqv.soctrang@gmail.com
This post is so interactive and informative.keep update more information...
ReplyDeleteDigital Marketing Course in Tambaram
Digital Marketing Course in Chennai
Great post. keep sharing such a worthy information.
ReplyDeleteGoogle Analytics Training In Chennai
Google Analytics Online Course