Keras Implementation of model - Week 2 Assignment

Hello,

I’m currently on the ML course 2 week 2 assignment, and implementing the model using keras sequential model. I did the whole thing as should be, even specified the number of neurons as the ‘units’ arg ie ‘units = 25’ for example. However, it returns this every time I submit:
ValueError: This model has not yet been built. Build the model first by calling build() or by calling the model on a batch of data.

Hi @Chukwuka_Chikwendu

please Make sure you pass all test cases and Run all cell without raising any error and after that try to submit again.
Thanks!
Abdelrahman

So you created the model using the keras.Sequential api. You added some layers to it.

Once you have defined your model, you need to compile it before you can train it. This is done using the compile method, which requires you to specify the loss function and the optimizer to use. For example:

Compile the model

model.compile(loss=‘categorical_crossentropy’, optimizer=‘adam’)

To train the model, you can use the fit method, which requires you to specify the training data and the number of epochs to train for. For example:

Train the model on a dataset of (input, output) pairs

model.fit(x, y, epochs=10)

This is a run down on the steps to create, compile, and train a model using keras.

Does this help you with your issue?

Juan

The compile() and fit() methods are used later in the notebook. That code is provided for you, you don’t have to write that code yourself.

However, it returns this every time I submit:
ValueError: This model has not yet been built. Build the model first by calling build() or by calling the model on a batch of data.

Please post a screen capture image that shows your grader message.