0
$\begingroup$

I am working on a multivariate binary classification problem. What I want to do is to predict a binary classification given the features at the current timestep and the data (features+real classification) from past timesteps

Keras seems to have a problem with the shape of my inputs so I want to know what I am doing wrong:

X_train = (nb_samples, nb_timesteps, nb_features) 
y_train = (nb_samples, nb_timesteps, binary_result)

model = Sequential() 
model.add(LSTM(nb_units,
               input_shape = X_train.shape[1:]
              )) 
Dense(1,activation='softmax')  
model.compile(loss='categorical_crossentropy',optimizer='adam',metrics=['accuracy']) 

history = model.fit(X_train, y_train, epochs=ep, validation_data=(X_train, y_train), verbose=2, shuffle=False)
$\endgroup$
0
$\begingroup$

Since you want to get a classification/output per each time step, you should set return_sequences=True in you LSTM layer.

Read more about return_sequences here in LSTM documentation.

$\endgroup$
0
$\begingroup$

Try the following code.

import keras

X_train = (nb_samples, nb_timesteps, nb_features) 
y_train = (nb_samples, nb_timesteps, binary_result)

model = keras.models.Sequential()
model.add(keras.layers.LSTM(nb_timesteps, input_shape = X_train.shape[1:]))
model.add(keras.layers.Dense(1, activation="sigmoid"))
model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])
model.summary()
history = model.fit(X_train, y_train, batch_size=32, epochs=ep, validation_split=0.2, verbose=2, shuffle=False)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy