I’m working on an LSTM model for time-series forecasting.
My dataset has two variables that include sales values for two companies. The dataset has ten rows. I wanted to forecast the 11th row. As the output for both of the variables, I end up getting the same tensor value. Any ideas on what I have missed and how to improve the results?
The inputs tensor, label tensor, output tensor are as follows.
Inputs:
tensor([[ 1431, 1424, 1483, ..., 1432, 1334, 1413],
[11574, 11613, 11671, ..., 11597, 11628, 11644]])
Label(11th row values): tensor([ 1472, 11602])
Output what I’m getting is: tensor([5893.2, 5893.2])
My nn.LSTM class is as follows.
class LSTMnn(L.LightningModule):
def __init__(self):
super().__init__()
self.lstm = nn.LSTM(input_size=1, hidden_size=256, num_layers=16)
self.lstm1 = nn.LSTM(input_size=256, hidden_size=128, num_layers=16)
self.lstm2 = nn.LSTM(input_size=128, hidden_size=64, num_layers=10)
self.lstm3 = nn.LSTM(input_size=64, hidden_size=32, num_layers=10)
self.lstm4 = nn.LSTM(input_size=32, hidden_size=8, num_layers=10)
self.linear = nn.Linear(8, 1)
self.loss_fn = nn.MSELoss()
def forward(self,input):
lstm_out, _ = self.lstm(input.view(len(input), 1, -1))
lstm_out, _ = self.lstm1(lstm_out)
lstm_out, _ = self.lstm2(lstm_out)
lstm_out, _ = self.lstm3(lstm_out)
lstm_out, _ = self.lstm4(lstm_out)
prediction = self.linear(lstm_out[-1].view(1, -1))
return prediction
def configure_optimizers(self):
return Adam(self.parameters(), lr=0.1)
def training_step(self, batch, batch_idx):
input_i, label_i = batch
output_i = self.forward(input_i[0])
loss = self.loss_fn(output_i, label_i)
self.log('train_loss', loss, on_step=True, on_epoch=True, prog_bar=True)
return loss```