ValueError: Exception encountered when calling layer "sequential_5" (type Sequential) ERROR

Viewed 13

Creating the model

#Set the random seed

tf.random.set_seed(42)

#Create a neural classification

classi_model1=tf.keras.Sequential([
        tf.keras.layers.Dense(100,activation='relu'),
        tf.keras.layers.Dense(1,activation='softmax')
    ])

#Compile the model
classi_model1.compile(loss=tf.keras.losses.BinaryCrossentropy(),
                      optimizer = tf.keras.optimizers.Adam(),
                      metrics=["accuracy"])

#Fit the model
classi_model1.fit(X,y,epochs=50,verbose=0)

#Evaluate the model
classi_model1.evaluate(X,y)

> Using same model for regression problem

#Let's see if our model is working for regression problem

tf.random.set_seed(42)

#Create some regression data
X_regression = tf.range(0,1000,5)
y_regression = tf.range(100,1100,5) #y=X+100

#Split our regression data into training data 
X_train = X_regression[:150]
X_test = X_regression[150:]
y_train = y_regression[:150]
y_test = y_regression[150:]

X_train = tf.convert_to_tensor(X_train)
y_train = tf.convert_to_tensor(y_train)

#Fit the regression data to classification model
   classi_model1.fit(X_train, y_train, epochs=100)


Error image
  [1]: https://i.stack.imgur.com/2io31.png
0 Answers
Related