I am implementing a lstm model with keras.
There are 11200 lines in my dataset and 5 columns. Each data is a vector. The shape of the dataset is (11200, 5, 54) and it looks like this.
col1 col2 col3 col4 col5
[1,3,...,-999] [2,4,...,-999] [3,4,...,-999] [5,6,...,-999] [4,5,...,-999]
[0,2,...,-999] [1,5,...,-999] [1,24,...,-999] [11,7,...,-999] [-1,4,...,-999]
...
[0,2,...,5] [1,5,...,8] [1,24,...,6] [11,7,...,5] [-1,4,...,2]
The length of each vector like this one [1,3,...,-999] is 54.
The target is a boolean vector of size (11200, 1) like this
1 T
2 F
... ...
11200 F
I created my model like this:
X_train, X_test, y_train, y_test = train_test_split(data,target, test_size=0.2, random_state=1)
batch_size = 32
timesteps = None
output_size = 1
epochs=120
inputs = Input(batch_shape=(batch_size, timesteps, output_size))
lay1 = LSTM(20, stateful=True, return_sequences=True)(inputs)
output = Dense(units = output_size)(lay1)
regressor = Model(inputs=inputs, outputs = output)
regressor.compile(optimizer='adam', loss = 'mae')
regressor.summary()
for i in range(epochs):
print("Epoch: " + str(i))
regressor.fit(X_train, y_train, shuffle=False, epochs = 1, batch_size = batch_size)
regressor.reset_states()
The problem is I have this error :
ValueError: Error when checking input: expected input_1 to have shape (None, 1) but got array with shape (5, 54).
What is wrong? The input or the output ? How can I feed the wrong one ?
Thanks.
timesteps = Nonebut you feed 5 to it, try to changetimestepsto 0inputs = Input(batch_shape=(batch_size, timesteps, output_size))which is the same asinputs = Input(batch_shape=(32, None, 1))Try changing Timesteps to 5, and output_size to 54. Though why you have output_size as input, I'm not sure.