下面是单步单维预测模型的数据结构,如果改为多步预测,结构如何修改: s = self.ps*self.skip + self.Ck-1 + self.h-1 X1 = np.zeros((self.n-s, self.w, self.m)) # short term dataset X2 = np.zeros((self.n-s, self.ps*self.Ck, self.m)) # long term dataset Y = np.zeros((self.n-s, self.m)) # output dataset for i in range(s, self.n): t = i-self.h+1 X1[i-s] = self.raw[t-self.w:t].copy() idx = [] for k in range(self.ps): # 执行4次,每次间隔skip长,取Ck=6, total = 4 * 6 = 24 idx = list(range(t-self.Ck-k*self.skip, t-k*self.skip)) + idx idx = np.array(idx, dtype=int) X2[i-s] = self.raw[idx].copy() Y[i-s] = self.raw[i].copy() return X1, X2, Y
时间: 2024-02-14 07:17:28 浏览: 66
如果要改为多步预测,需要修改输出数据集Y的维度,变成一个矩阵,其中每一行表示从当前时间步开始的未来若干时间步的预测值。同时,由于需要预测多个时间步,长期数据集X2也需要进行相应的修改,变成一个三维数组,其中第一维表示时间步,第二维表示长期时间窗口,第三维表示特征数量。修改后的代码如下:
```
s = self.ps*self.skip + self.Ck-1 + self.h-1
X1 = np.zeros((self.n-s, self.w, self.m)) # short term dataset
X2 = np.zeros((self.n-s, self.ps, self.Ck, self.m)) # long term dataset
Y = np.zeros((self.n-s-self.h+1, self.h, self.m)) # output dataset
for i in range(s, self.n):
t = i-self.h+1
X1[i-s] = self.raw[t-self.w:t].copy()
idx = []
for k in range(self.ps):
idx = list(range(t-self.Ck-k*self.skip, t-k*self.skip)) + idx
idx = np.array(idx, dtype=int)
X2[i-s] = self.raw[idx].reshape(self.ps, self.Ck, self.m).copy()
Y[i-s-self.h+1] = self.raw[i-self.h+1:i+1].copy()
return X1, X2, Y
```
阅读全文