Binary classification error - tensorflow - fit method

Hello, before advancing in the course, I wanted to put into practice the knowledge I’ve got until now.
I’m doing the titanic exercise that you can determine if the person could have survived or not.

Everything is OK until I call the fit method. I’m receiving an error.

Step by step:

Error:

What am I doing wrong?

Thanks.
Regards.
Gus

Looks like your Sequential model summary is incorrect - it only has one Dense layer, you specfied that you wanted three.
And the one layer it has is the wrong shape (two “None” isn’t right).

Did you clear the kernel and re-run all of the cells since your last edit?

Hi @TMosh ,

This is the complete layers:

The input is a matrix of 836 rows per 5 columns/features

Should I indicate rows and columns? Like this:

model = Sequential(
[
tf.keras.Input(shape=(836,5)),
Dense(units=25, activation=‘relu’),
Dense(units=15, activation=‘relu’),
Dense(units=1, activation=‘sigmoid’)
]
)

Regards.
Gus

Hi @TMosh ,

With this approach it works:

model = Sequential()
model.add(Dense(5, activation = ‘relu’, input_dim = 5))
model.add(Dense(5, activation = ‘relu’))
model.add(Dense(1, activation = ‘sigmoid’))

model.summary()

Result:

but it says this warning:

“Warning: Do not pass an input_shape/input_dim argument to a layer. When using Sequential models, prefer using an Input(shape) object as the first layer in the model instead”

How can I use Input(shape)? What is the correct format to indicate 5 features?

Thanks.
Regards.
Gus

With the Sequential model, you don’t need to specify an input layer or shape. TF will figure the input size when you fit the model and provide the data set.

See the Machine Learning Specialization, Course 2, Week 3.

Hello, Gus @gmazzaglia,

image

Just give it the shape of one sample: (5, ).

Cheers,
Raymond

1 Like

Thansks @rmwkwok, it works.

Regards.
Gus

1 Like