主要改动是调用nn.LSTM时,将batch_first打开(即batch_size = first),原因是当使用torch.utils.data.DataLoader时,产生的三维数组,总是以bactch_size 开头的,
self.lstm = nn.LSTM(input_size=3, hidden_size=256, num_layers=1,batch_first = True)
其次,改动为forward函数,将
x = self.linear(x)放到 x = x[:, -1, :]前
原因是x.shape,看图,当时是看print进行改正的
从[batch_size , lookback,feature]到[batch_size,lookback,num_of_hiddensize] 到[batch_size,last_one]
这样是合理的变化
但是然后效果没咋变
还是拟合得不太好
代码地址
https://github.com/Tangxiwei/PythonCode/tree/master/pytorch