Hi I am trying to use a stacked LSTM architecture in keras, similar to what is shown here https://keras.io/getting-started/sequential-model-guide/. My problem is formulated as a binary time series classification, my timesteps are 2 and I have 7 attributes. The shape of my data is as follows:- X_train_smote_reshaped (1256L, 2L, 7L) y_train_smote_reshaped (1256L, 2L) X_validation_std_reshaped (168L, 2L, 7L) y_validation_reshaped (168L, 2L)
The error I get is: Exception: Error when checking model target: expected dense_1418 to have shape (None, 1) but got array with shape (1256L, 2L)
My keras code is listed below:
from keras.layers import LSTM
X_train_smote_reshaped=np.array([X_train_smote_std[i:i+2] for i in range(len(X_train_smote_std)-2)])
y_train_smote_reshaped=np.array([y_train_smote[i:i+2] for i in range(len(y_train_smote)-2)])
X_validation_std_reshaped=np.array([X_validation_std[i:i+2] for i in range(len(X_validation_std)-2)])
y_validation_reshaped=np.array([y_validation[i:i+2] for i in range(len(y_validation)-2)])
data_dim=7
timesteps=2
#1.define the network
model=Sequential()
model.add(LSTM(20,return_sequences=True,input_shape=(timesteps,data_dim)))
model.add(LSTM(20))
#one neuron in the output layer with a sigmoid activation function
model.add(Dense(1,activation='sigmoid'))
#2. compile the network
model.compile(loss='binary_crossentropy',optimizer='adam',metrics=['accuracy'])
#3. fit the model
model.fit(X_train_smote_reshaped,y_train_smote_reshaped,batch_size=64,nb_epoch=5,validation_data=(X_validation_std_reshaped,y_validation_reshaped))