0
model = Sequential()
model.add(Conv1D(filters=4, kernel_size=(1), activation="relu", input_shape=(4,1)))
model.add(MaxPooling1D(pool_size=(1)))
model.add(Dropout(0.25))
model.add(Conv1D(filters=32, kernel_size=(1), activation='relu'))
model.add(MaxPooling1D(pool_size=(1)))
model.add(Dropout(0.25))
model.add(Conv1D(filters=64, kernel_size=(1), activation="relu"))
model.add(MaxPooling1D(pool_size=(1)))
model.add(Dropout(0.25))
model.add(Conv1D(filters=64, kernel_size=(1), activation='relu'))
model.add(MaxPooling1D(pool_size=(1)))
model.add(Dropout(0.25))
model.add(Flatten())
model.add(Dense(128, activation='relu'))
model.add(Dropout(0.5))
model.add(Dense(64, activation='relu'))
model.add(Dropout(0.5))
model.add(Flatten())
model.add(Dense(7, activation='sigmoid'))
model.compile(optimizer='adam', loss='binary_crossentropy', metrics=['accuracy'])

Hello, I'm new to building neural networks and decided to try my hand solving a multi-label classification problem. I'm take four feature values as input and giving the resulting classification as one or more of 7 categories. As such, I decided to implement the neural network as seen above. However, upon fitting the model

model.fit(X_train, y_train, epochs = 10, validation_data = (X_test,y_test), batch_size = 64)

I receive this error:

Error when checking input: expected conv1d_92_input to have 3 dimensions, but got array with shape (415, 4)

I'm confused as to watch to do in order to get the neural network to fit to the data. The shape of feature and label data respectively are : X_train = (414,4) y_train = (413,7)

  • Sorry, but you should really review basics of neural networks before writing code like this. Why do you use convolution with just four inputs? Are you aware of what a convolution with filter size 1 means? What's the point of using pooling with size 1 (it doesn't do anything)? ... As for the error, well, the input shape you specify in the model is clearly different from the shape of the data. It's easy to fix in principle (just add an axis to the data at the end) but I doubt that will really "help" you in the long run. – xdurch0 Jun 17 '20 at 21:16
  • I was told a convolution should be used for problems like this and not a recurrent neural network instead because it isn't dealing with a time series of any sort. Also i used a filter size of 4, and in the model given after convolution is generally pooling. Which is why i used a pooling. – Karry Alams Jun 17 '20 at 21:21

1 Answers1

0

I believe you might find this previous stack stackoverflow post (It seems to be addressing your question) helpful: Error when checking model input: expected lstm_1_input to have 3 dimensions, but got array with shape (339732, 29)

Kehinde
  • 16
  • 3