0
$\begingroup$

Create model:

model=Sequential()
model.add(Dense(input_dim = 12, units = 10, activation='relu', kernel_initializer='uniform'))
model.add(Dense(units = 8, activation='relu', kernel_initializer='uniform'))
model.add(Dense(units = 1, activation='sigmoid', kernel_initializer='uniform'))

print('Training the model...')

Compile model:

model.compile(optimizer='adam', loss='binary_crossentropy', metrics=['accuracy'])

while running the model.fit()

Fit the model:

model.fit(X_train,y_train,batch_size=32, epochs=10, verbose=1)

I am getting the error:

ValueError: Error when checking input: expected dense_36_input to have shape 
(None, 12) but got array with shape (140, 2)
$\endgroup$
1
  • $\begingroup$ Your data has a shape of (140, 2 ) instead of 2 we require 12 here. Reshape your data with numpy.reshape $\endgroup$ Commented Apr 25, 2019 at 7:03

1 Answer 1

0
$\begingroup$

Input dimension means the number of features or columns that your input is supposed to have.

The neural network will try to adjust to this input shape. In your case, you have specified input_dim = 12, but in your data (140,2) there are only 2 features or columns.

So there are two options:

  1. Set input_dim =2

  2. Reshape the input array to be in multiples of specified input dimension i.e. 12.

In your case, ONLY option 1 works because (140,2) cannot be reshaped into multiples of 12.

Note: other valid input_dim for you could be 14 (reshape input to (20,14)), 10 (reshape input to (28,10))

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.