Advertisement

TrimwebsolutionsTrimwebsolutions

Problem and Solutions

Trying to copy a LSTM model - it's not working in python ?

By M.K. Verma · 3 May 2022

Trying to copy a LSTM model - it's not working in python ?

To add to the other answer, the train and test sets are built here:

num = int(data_reframed.shape[0]*0.8)
value = data_reframed.values
train = value[:num, :]
test = value[num:, :]

train_x, train_y = train[:, :-1], train[:, -1]
test_x, test_y = test[:, :-1], test[:, -1]

While yPredict is calculated here:

yPredict = Model.predict(test_x)

Hence, the shape of yPredict and test_y has to be the same, and that has to be (data_reframed.shape[0] - num,), since num is the size of the training set. So, you can write:

plt.plot(data.index[num:], test_y, color='blue',label='Actual')
plt.plot(data.index[num:], yPredict, alpha=0.7, color='red',label='Predict')