参考网址:
适用场景:
具有周期性的数据的预测,平滑因子,季节平滑因子,趋势平滑因子通过反复测试,比较方差最小的为最佳预测。
实现代码:
import java.util.ArrayList;
import java.util.List;
/**
* 三次指数平滑预测,最多外推一个周期
* @author Administrator
*
*/
public class HoltWintersTripleExponentialImpl {
static double[] alphas=new double[]{0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9};
public static Double getbetterforecast(List<Integer> y, int period, int m) {
double[] result=betterforecast(y,period,m);
return result[result.length-1];
}
/**
* 求出最佳预测
* @param y
* @param alpha
* @param beta
* @param gamma
* @param period
* @param m
* @param debug
* @return
*/
public static double[] betterforecast(List<Integer> y, int period, int m) {
double[] result = null;
double avg=0;
for(int i=0;i<alphas.length;i++){
int sum=0;
double[] temp=forecast(y,alphas[i],0.25,0,period,m,false);
for(int j=0;j<y.size();j++){
sum+=Math.abs(y.get(j)-temp[j]);
}
if(i==0){
avg=sum/y.size();
result=temp;
}
if(avg<(sum/y.size())){
result=temp;
}
}
return result;
}
/**
* This method is the entry point. It calculates the initial values and returns the forecast
* for the m periods.
* @param y 数据集合
* @param alpha - Exponential smoothing coefficients for level, trend, seasonal components.
* @param beta - Exponential smoothing coefficients for level, trend, seasonal components.
* @param gamma - Exponential smoothing coefficients for level, trend, seasonal components.
* @param perdiod - 一个完整周期的长度,至少需要两个周期
* @param m -预测的个数
* @param debug - 是否打印详细信息