python 指数平滑简单使用
# 平滑指数 def calc_next_s(alpha, x): s = [0 for i in range(len(x))] s[0] = np.sum(x[0:3]) / float(3) for i in range(1, len(s)): s[i] = alpha*x[i] + (1-alpha)*s[i-1] return s # 预测 def time_predict(x):
alpha = 0.8 s1 = calc_next_s(alpha, x) # 一次 s2 = calc_next_s(alpha,s1) # 二次 s3 = calc_next_s(alpha, s2) # 三次 a3 = [(3 * s1[i] - 3 * s2[i] + s3[i]) for i in range(len(s3))] b3 = [((alpha / (2 * (1 - alpha) ** 2)) * ((6 - 5 * alpha) * s1[i] - 2 * (5 - 4 * alpha) * s2[i] + (4 - 3 * alpha) * s3[i])) for i in range(len(s3))] c3 = [(alpha ** 2 / (2 * (1 - alpha) ** 2) * (s1[i] - 2 * s2[i] + s3[i])) for i in range(len(s3))] pred = a3[-1]+b3[-1]*1+c3[-1]*(1**2) print(pred) if __name__ == "__main__: x = [] # x内填写需要预测的列表数据 time_predict(x)