Hi all. I have doubt in training an LSTM model for time series prediction. I have a dataset that looks like this:





Datetime
AEP_MW




0
2004-12-31 01:00:00
13478.0


1
2004-12-31 02:00:00
12865.0


2
2004-12-31 03:00:00
12577.0


3
2004-12-31 04:00:00
12517.0


4
2004-12-31 05:00:00
12670.0



I create train and test sets based on the dates and scale the values using Sklearn.
train_set = df[df['Datetime'] < '2017-1-1 00:00:00']
test_set = df[df['Datetime'] >= '2017-1-1 00:00:00']

After that, I create a data structure for the LSTM. I want the model to look at the previous 60 time steps to predict the next 1 time step.
X_train = []
y_train = []

window_size = 60
num_features = 1

for i in range(window_size, len(train_set)):
    X_train.append(train_vals_scaled[i-window_size:i, 0])
    y_train .append(train_vals_scaled[i, 0])

X_train, y_train = np.array(X_train), np.array(y_train)

After this, I write a Data Loader class.
class trainData(Dataset):
    
    def __init__(self, X_data, y_data):
        self.X_data = X_data
        self.y_data = y_data
        
    def __getitem__(self, index):
        return self.X_data[index], self.y_data[index]
        
    def __len__ (self):
        return len(self.X_data)

    
class testData(Dataset):
    
    def __init__(self, X_data):
        self.X_data = X_data
        
    def __getitem__(self, index):
        return self.X_data[index]
        
    def __len__ (self):
        return len(self.X_data)

train_data = trainData(torch.FloatTensor(X_train), torch.FloatTensor(y_train))
test_data = testData(torch.FloatTensor(X_test))

I can’t seem to write code after this. I need help in writing the LSTM class along with training and prediction. The docs seem very confusing and I couldn’t find a good blogpost online which uses PyTorch for tabular time series forecasting.