My train set has 10 columns including a target column that I'm trying to predict, while my test set (dataframe_test
) has 9 columns. When I run the code I receive this error:
Input 0 of layer "Hidden1" is incompatible with the layer: expected axis -1 of input shape to have value 10, but received input with shape (None, 9)
Call arguments received:
• inputs=tf.Tensor(shape=(None, 9), dtype=float64)
• training=False
• mask=None**
My model looks like this:
model = tf.keras.models.Sequential()
model.add(tf.keras.layers.Dense(units=10,
activation='relu',
kernel_regularizer=tf.keras.regularizers.l2(l=0.01),
name='Hidden1'))
model.add(tf.keras.layers.Dense(units=6,
activation='relu',
kernel_regularizer=tf.keras.regularizers.l2(l=0.01),
name='Hidden2'))
model.add(tf.keras.layers.Dense(units=1,
name='Output'))
my_learning_rate = 0.3
model.compile(optimizer=tf.keras.optimizers.Adam(learning_rate=my_learning_rate),
loss="categorical_crossentropy",
metrics='accuracy')
epochs = 10
batch_size = 32
history = model.fit(train, y_train, epochs = epochs, batch_size = batch_size)
epochs = history.epoch
print(epochs)
score = model.predict(dataframe_test)
CodePudding user response:
Try using sigmoid
input_size=len(X.columns)
model.add(Dense(10,activation='sigmoid', input_shape=(input_size,)))
model.add(Dense(10,activation='relu'))
model.add(Dense(10,activation='relu'))
model.add(Dense(1))
CodePudding user response:
You must to split your train set in a 9 columns input matrix x_train = train[:, :10]
and a single column training target matrix y_train = train[:, 10].reshape((-1, 1))
.