I have fitted a lstm model. There are 100 observations for each x and y variables. I used 80 values to train the model and 20 values to evaluate the model.
import numpy as np
import tensorflow as tf
from tensorflow import keras
from tensorflow.keras import layers
from tensorflow.keras import Sequential
from tensorflow.keras.layers import Dense, LSTM, Dropout
input_features=1
time_stamp=100
out_features=1
x_input=np.random.random((time_stamp,input_features))
y_input=np.random.random((time_stamp,out_features))
train_x=x_input[0:80,:]
test_x=x_input[80:,:]
train_y=y_input[0:80,:]
test_y=y_input[80:,:]
Then I reshaped the data as it necessary to do so before feeding the data into LSTM function.(Ex: For training x:(samples, timesteps, features)=(1,80,1))
dataXtrain = train_x.reshape(1,80, 1)
dataXtest = test_x.reshape(1,20,1)
dataYtrain = train_y.reshape(1,80,1)
dataYtest = test_y.reshape(1,20,1)
dataXtrain.shape
(1, 80, 1)
Then I was able to fit the model successfully using following lines of code:
model = Sequential()
model.add(LSTM(20,activation = 'relu', return_sequences = True,input_shape=(dataXtrain.shape[1],
dataXtrain.shape[2])))
model.add(Dense(1))
model.compile(loss='mean_absolute_error', optimizer='adam')
model.fit(dataXtrain, dataYtrain, epochs=100, batch_size=10, verbose=1)
But when I predict the model for the test data, I am getting this error.
y_pred = model.predict(dataXtest)
Error when checking input: expected lstm_input to have shape (80, 1) but got array with shape (20, 1)
Can anyone help me to figure out what is the problem here?
Thank you