Search code examples
pythonkerasneural-network

TypeError: Sequential.__init__() takes from 1 to 3 positional arguments but 4 were given


Am not able to declare the model due to problems in input_shape

input_shape = [x_train_scaled.shape[1]]
input_shape

Output - [6]

model = tf.keras.Sequential(
    tf.keras.layers.Dense(units=64, input_shape=input_shape, activation='relu'),
    tf.keras.layers.Dense(units=64, activation='relu'),
    tf.keras.layers.Dense(units=1)
)
model.summary()

Error shown : TypeError: Sequential.init() takes from 1 to 3 positional arguments but 4 were given

I was trying to declare a sequential model but am getting typeError


Solution

  • From https://www.tensorflow.org/api_docs/python/tf/keras/Sequential#args_1 :

    layers: Optional list of layers to add to the model

    you need to pass your layers as a list when instantiating the sequential object Instead of individual arguments like you are doing now:

    tf.keras.Sequential(
        layers=[
            tf.keras.layers.Dense(units=64, input_shape=input_shape, activation='relu'),
            tf.keras.layers.Dense(units=64, activation='relu'),
            tf.keras.layers.Dense(units=1)
        ],
        name=None
    )