I have this LSTM model
model = Sequential()
model.add(Masking(mask_value=0, input_shape=(timesteps, features)))
model.add(LSTM(100, dropout=0.2, recurrent_dropout=0.2, return_sequences=False))
model.add(Dense(features, activation='softmax'))
model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])
and shapes X_train (21, 11, 5), y_train (21, 5)
.
Each timestep is represented by 5 features and
return_sequences
is set to False
because I want to predict one 5D array (the next timestep) for each input sequence of 11 timesteps.
I get the error
ValueError: y_true and y_pred have different number of output (5!=1)
If I reshape the data as X_train (21, 11, 5), y_train (21, 1, 5)
instead I get the error
ValueError: Invalid shape for y: (14, 1, 5)
Note: the value 14 is due to the fact that I'm using cross validation.
What should I do?
Edit
I changed the model to
model = Sequential()
model.add(Masking(mask_value=0, input_shape=(timesteps, features)))
model.add(LSTM(100, dropout=0.2, recurrent_dropout=0.2))
model.add(Dense(features, activation='sigmoid'))
model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])
and used the same shapes as before.
Here model.summary()
gives
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
masking_1 (Masking) (None, 11, 5) 0
_________________________________________________________________
lstm_1 (LSTM) (None, 100) 42400
_________________________________________________________________
dense_1 (Dense) (None, 5) 505
=================================================================
The idea is to produce a multilabel classification. After training the model, I evaluate it on the test data and this is what I get:
X[0] = [[0 0 0 0 0],[1 0 0 1 0], ...,[0 0 1 0 0],[0 0 1 0 0]]
y_true[0] = [0 0 1 0 0]
y_pred[0] = 2
which is not what I want. How can I get an output of the same shape as y_true, so as to transform it into a multilabel classification?