hassan yassin
hassan yassin

Reputation: 47

why I'm getting this error "Input 0 of layer "dense_30" is incompatible with the layer:expected min_ndim=2,found ndim=1. Full shape received: (None,)"

Set random seed

print(np.__version__) tf.random.set_seed(42)
  1. Create a model using the Sequential Api

     model = tf.keras.Sequential([tf.keras.layers.Dense(1)])
    
  2. Compile the model

     model.compile(loss=tf.keras.losses.mae,# mae is short for mean absolute error
     optimizer = tf.keras.optimizers.SGD(), # sgd is short for stochastic gradient descent             
     metrics=["mae"] 
    
  3. Fit the model

     model.fit(X, y, epochs=5) // here the error
    

Upvotes: 0

Views: 540

Answers (1)

Kudo
Kudo

Reputation: 337

You need to add an input layer, ex:

model = tf.keras.Sequential([  tf.keras.layers.InputLayer(input_shape=(1,)),  tf.keras.layers.Dense(1) ])

Upvotes: 1

Related Questions