Full error:
ValueError: Input 0 of layer sequential is incompatible with the layer: expected
axis -1 of input shape to have value 20 but received input with shape (None, 1)
The Issue
I have been struggling a lot with setting up a neural network as it constantly complains about the shape received. The x_trian and y_train both have a shape of (20,) but when I input that as the input_shape it says it expected the input shape to have value 20 but instead recieved (None,1).
I do not undersatnd where the (None,1) is coming from because when I print the shape of both the x_train and y_train it gives me (20,). They are both numpy arrays.
The Code
# (the training_data and testing_data are both just numpy arrays with 0 being the data and 1 being the label)
x_train = training_data[:, 0] # training feature
y_train = training_data[:, 1] # training label
x_test = testing_data[:, 0] # testing feature
y_test = testing_data[:, 1] # testing label
# Create neural network.
from keras.models import Sequential
from keras.layers import Dense
model = Sequential()
model.add(Dense(16, input_dim=20, activation='relu', input_shape=(20,)))
model.add(Dense(12, activation='relu'))
model.add(Dense(12, activation='relu'))
model.add(Dense(2, activation='softmax'))
model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])
What I tried
I then changed the input_shape to (None,1) but then it said:
ValueError: Shapes (None, 1) and (None, 1, 2) are incompatible
So, I then changed it to (None, 1, 2) and then it said:
ValueError: Input 0 of layer sequential is incompatible with the layer: expected
axis -1 of input shape to have value 2 but received input with shape (None, 1)
Which then sends back me to the original error.
I then found that (20,) is only a dimension of 1 so I changed the input_dim to 1 and got:
ValueError: Input 0 of layer sequential is incompatible with the layer: expected
axis -1 of input shape to have value 20 but received input with shape (None, 1)
Conclusion
I am almost certain it has to do with the input_dim, input_shape or the Dense unit (which is 16 on the first model.add (the one the errors complain about) but I am very unsure how to change the values to fit my data.
I know the shape is (20,) and I know the dimension is 1, so it might just have to do with the Dense unit's value (which is 16 on the first model.add which is what the compiler complains about). I read up about what the units measure it but still strugle to understand it.