Complete the code to create a binary classification model using TensorFlow Keras.
model = tf.keras.Sequential([
tf.keras.layers.Dense(16, activation='relu', input_shape=(10,)),
tf.keras.layers.Dense(1, activation=[1])
])For binary classification, the output layer uses a sigmoid activation to output probabilities between 0 and 1.
Complete the code to compile the binary classification model with the correct loss function.
model.compile(optimizer='adam', loss=[1], metrics=['accuracy'])
Binary classification models use 'binary_crossentropy' as the loss function.
Fix the error in the code to correctly train the binary classification model.
history = model.fit(X_train, y_train, epochs=[1], batch_size=32)
The number of epochs must be an integer, not a string or None.
Fill both blanks to evaluate the model on test data and print accuracy.
loss, [1] = model.evaluate(X_test, y_test) print('Test [2]:', [1])
The evaluate method returns loss and accuracy. We assign accuracy to a variable and print it.
Fill all three blanks to predict classes for new data and convert probabilities to binary labels.
predictions = model.predict([1]) binary_predictions = (predictions [2] 0.5).astype([3])
We predict on new data X_new, compare probabilities to 0.5 to get True/False, then convert to integers 0 or 1.