I am working on a machine learning project and I want to make a neural network my purpose. Below is the code of my model, it is working fine with Dense
layer but is is giving error with LSTM
layer
model = keras.Sequential([
layers.LSTM(512, activation='relu', input_shape=X_train.shape),
layers.Dropout(0.4),
layers.Dense(512, activation='relu'),
layers.Dropout(0.4),
layers.Dense(512, activation='relu'),
layers.Dropout(0.4),
layers.Dense(512, activation='softmax'),
layers.Dropout(0.4),
layers.Dense(6)
])
model.compile(
optimizer="adam",
loss="rmse",
metrics=['accuracy']
)
history = model.fit(X_train, y_train,epochs=100,batch_size=4200)
Error message
ValueError: Input 0 of layer sequential_9 is incompatible with the layer: expected ndim=3, found ndim=2. Full shape received: (4200, 25)
CodePudding user response:
Before fitting the model I reshaped the training and testing dataset as directed by Frightera as
X_train=np.expand_dims(X_train, axis=-1)
X_test=np.expand_dims(X_test, axis=-1)