时间序列预测模型

1.一次移动平均预测法

        设时间序列为\{y_{t}\},取移动平均的项数为n,则第t+1期预测值的计算公式为:

        \widehat{y_{t+1}} ={M_{t}}^{(1)}= \frac{y_t + y_{t-1} + y_{t-2} + \ldots + y_{t-n+1}}{n}=\frac{1}{n}\sum_{j=1}^{n}y_{t-n+j}

        其中,y_{t}表示第t期实际值,{M_{t}}^{(1)}表示第t期一次移动平均数,\widehat{y_{t+1}}表示第t+1期预测值(t\geq n)

        预测的标准误差为:

S=\sqrt{\frac{\sum_{t=n-1}^{N-2}(\widehat{y_{t+1}}-y_{t+1})^{2} }{N-n}}

        一次移动平均预测法是一种简单的预测方法,它没有考虑到时间序列数据的趋势和季节性等特征,误差较大,在建模中并不常用。

例:

t 0 1 2 3 4 5 6 7 8 9 10
y_{t} 533.8 574.6 606.9 649.8 705.1 772.0 816.4 892.7 963.9 1015.1 1102.7

        计算\widehat{y_{11}}及标准误差。

示例代码:

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期预测值的计算公式:

        \widehat{y_{t+1}}=\frac{W_{1}y_{t}+W_{2}y_{t-1}+\cdots+W_{n}y_{t-n+1}}{W_{1}+W_{2}+\cdots+W_{n}}=\frac{\sum_{i=1}^{n}W_{i}y_{t-i+1}}{\sum_{i=1}^{n}W_{i}}

        标准误差的计算方法与一次移动平均预测法相同。

例:在上一个例题的基础上,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.指数平滑预测法

        在加权一次移动平均预测法的基础上,y_{t-i}的权数为\alpha (1-\alpha )^{i}。以此类推,第t+1期预测值的计算公式:

\widehat{y_{t+1}}=S_{t}^{(1)}=\alpha y_{t} + (1-\alpha )S_{t-1}^{(1)}

        S_{t}^{(1)}表示t期一次指数平滑值,\alpha表示平滑系数,(0<\alpha <1)。指数平滑预测法平滑值的计算还需要给出一个初始值S_{0}^{(1)},可取原时间序列的第一项或前几项的算数平均值为初值。

例:下表数据是

  • 39
    点赞
  • 24
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值