I am trying deep learning (noob) with Keras. I was trying to creat the model after loading my dataset (training & testing). My code:
scaler = StandardScaler().fit(train)
train=scaler.transform(train)
test=scaler.transform(test)
# Creating Deep Model
model = Sequential()
# Add an input layer
model.add(Dense(12, activation='relu', input_shape=(11,)))
# Add one hidden layer
model.add(Dense(8, activation='relu'))
# Add an output layer
model.add(Dense(1, activation='sigmoid'))
#add improvements
model.add(BatchNormalization())
model.add(Dropout(0.5))
#Train the model
model.compile(loss='binary_crossentropy',optimizer='adam',metrics=
['accuracy'])
model.fit(train,train_targets,epochs=20, batch_size=1, verbose=1)
However, I am recieving an erro at the last line:
ValueError: Error when checking input: expected dense_1_input to have shape (11,) but got array with shape (211,)
what does the error mean? and what could be causing it?
It means that you set your first layer to expect input shape (11,) by setting the hyperparameter to input_shape = (11,)
and you later gave the model a shape equal to train
. Try using: train.shape
and check for the shape to make sure the model can work with it. You might want check this answer Keras input explanation: input_shape, units, batch_size, dim, etc to make sure you understand the core concepts of a neural network hyperparameters.