【发布时间】:2025-04-20 12:10:02
【问题描述】:
我创建了一个简单的 LSTM 模型来预测优衣库的收盘价。问题是,我的模型似乎没有学到任何东西。这是我的notebook的链接
这是我的模型创建类(我之前试过relu激活函数,结果一样):
class lstm(torch.nn.Module):
def __init__(self,hidden_layers):
super(lstm,self).__init__()
self.hidden_layers = hidden_layers
self.lstm = torch.nn.LSTM(input_size = 2,hidden_size = 100,num_layers = self.hidden_layers,batch_first=True)
self.hidden1 = torch.nn.Linear(100,80)
self.dropout1 = torch.nn.Dropout(0.1)
self.hidden2 = torch.nn.Linear(80,60)
self.dropout2 = torch.nn.Dropout(0.1)
self.output = torch.nn.Linear(60,1)
def forward(self,x):
batch = len(x)
h = torch.randn(self.hidden_layers,batch,100).requires_grad_().cuda()
c = torch.randn(self.hidden_layers,batch,100).requires_grad_().cuda()
x,(ho,co)= self.lstm(x.view(batch,10,2),(h.detach(),c.detach()))
x = torch.reshape(x[:,-1,:],(batch,-1))
x = self.hidden1(x)
x = torch.nn.functional.tanh(x)
x = self.dropout1(x)
x = self.hidden2(x)
x = torch.nn.functional.tanh(x)
x = self.dropout2(x)
x = self.output(x)
return x
model = lstm(10)
这是我的训练损失图: training loss
这是我的验证损失图: validation loss
这是我的基本事实(蓝色)与预测(橙色): ground truth vs prediction
谁能指出我做错了什么?
【问题讨论】:
标签: python deep-learning pytorch artificial-intelligence