1.一次移动平均预测法
设时间序列为,取移动平均的项数为n,则第t+1期预测值的计算公式为:
其中,表示第t期实际值,表示第t期一次移动平均数,表示第t+1期预测值。
预测的标准误差为:
一次移动平均预测法是一种简单的预测方法,它没有考虑到时间序列数据的趋势和季节性等特征,误差较大,在建模中并不常用。
例:
t | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |
533.8 | 574.6 | 606.9 | 649.8 | 705.1 | 772.0 | 816.4 | 892.7 | 963.9 | 1015.1 | 1102.7 |
计算及标准误差。
示例代码:
import numpy as np
def calculate_y_hat(y, n, t):
y_hat = np.mean(y[t-n+1:t+1])
return y_hat
def calculate_standard_error(y, y_hat, n, t):
residuals = y[n:t+1] - y_hat
mean_squared_residuals = np.mean(residuals**2)
standard_error = np.sqrt(mean_squared_residuals)
return standard_error
# 示例数据
y = np.array([533.8, 574.6, 606.9, 649.8, 705.1, 772.0, 816.4, 892.7, 963.9, 1015.1,1102.7])
n = 4
t = 10
# 计算第 t+1 期的预测值
y_hat = calculate_y_hat(y, n, t)
print("第 t+1 期的预测值:", y_hat)
# 计算预测的标准误差
result = []
for i in range(n-1, t):
y_hat = calculate_y_hat(y, n, i)
result.append(y_hat)
standard_error = calculate_standard_error(y, result, n, t)
print("预测的标准误差:", standard_error)
2.加权一次移动平均预测法
第t+1期预测值的计算公式:
标准误差的计算方法与一次移动平均预测法相同。
例:在上一个例题的基础上,n=3,W=[3,2,1]。
示例代码:
import numpy as np
def calculate_y_hat(y, W, n, t):
numerator = np.sum(W[::-1] * y[t-n+1:t+1])
denominator = np.sum(W)
y_hat = numerator / denominator
return y_hat
def calculate_standard_error(y, y_hat, n, t):
residuals = y[n:t+1] - y_hat
mean_squared_residuals = np.mean(residuals**2)
standard_error = np.sqrt(mean_squared_residuals)
return standard_error
# 示例数据
y = np.array([533.8, 574.6, 606.9, 649.8, 705.1, 772.0, 816.4, 892.7, 963.9, 1015.1,1102.7])
W = np.array([3.0,2.0,1.0])
n = 3
t = 10
# 计算第 t+1 期的预测值
y_hat = calculate_y_hat(y,W, n, t)
print("第 t+1 期的预测值:", y_hat)
# 计算预测的标准误差
result = []
for i in range(n-1, t):
y_hat = calculate_y_hat(y, W, n, i)
result.append(y_hat)
standard_error = calculate_standard_error(y, result, n, t)
print("预测的标准误差:", standard_error)
3.指数平滑预测法
在加权一次移动平均预测法的基础上,的权数为。以此类推,第t+1期预测值的计算公式:
表示t期一次指数平滑值,表示平滑系数,。指数平滑预测法平滑值的计算还需要给出一个初始值,可取原时间序列的第一项或前几项的算数平均值为初值。
例:下表数据是