I am trying to use pytorch to make predictions on time-series dataset.
1- First, I splitted the dataset into training and test.
2- Then, I created the model.
import torch.nn as nn
import torch.nn.functional as F
class Model(nn.Module):
def __init__(self):
super(Model, self).__init__()
self.rnn = nn.LSTM(input_size=1,hidden_size=50,num_layers=3,batch_first=True,dropout=0.2)
self.out = nn.Linear(50, 1)
def forward(self, x):
r_out, (h_n, h_c) = self.rnn(x, None)
x = r_out[:,-1,:] #last hidden output!
x = self.out(x)
return x
model = Model()
if cuda:
model.cuda()
3- After training the model, I made the validation step.
mse = mean_squared_error(dataset['y'].iloc[60:].values,predicted)
print("RMSE:", np.sqrt(mse))
# RMSE: 0.10680269716212222
Question: I would like to know, how can I use this model to predict the next 60 days ?
I read that is necessary to: Take the last prediction value(i.e predicted[-1]) from my predictions and add it to the last array of total_x, excluding the first timestep.
So, I tried this:
#array --> List
today = total_x[-1].reshape(-1).tolist()
# scaling last price
last_price = scaler.transform(infered['y_pred'][-1].reshape(-1, 1))
# adding last price to list.
today.append(last_price[0])
# Exclude first(0th index) element
today = today[1:]
#reshape
today = np.array(today).reshape(-1,60,1)
today = torch.Tensor(list(today))
#predict!
tomorrow = predict_with_pytorch(model, today)
#inverse transform.
tomorrow = scaler.inverse_transform(tomorrow)[0]
This Variable tomorrow
is my tomorrow prediction, however, how to do this, for the next 60 days ?