0
0
TensorFlowml~10 mins

Binary classification model in TensorFlow - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a binary classification model using TensorFlow Keras.

TensorFlow
model = tf.keras.Sequential([
    tf.keras.layers.Dense(16, activation='relu', input_shape=(10,)),
    tf.keras.layers.Dense(1, activation=[1])
])
Drag options to blanks, or click blank then click option'
A'softmax'
B'sigmoid'
C'relu'
D'tanh'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'softmax' activation for a single output neuron.
Using 'relu' activation in the output layer.
2fill in blank
medium

Complete the code to compile the binary classification model with the correct loss function.

TensorFlow
model.compile(optimizer='adam', loss=[1], metrics=['accuracy'])
Drag options to blanks, or click blank then click option'
A'binary_crossentropy'
B'hinge'
C'mean_squared_error'
D'categorical_crossentropy'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'categorical_crossentropy' for binary classification.
Using regression loss functions like 'mean_squared_error'.
3fill in blank
hard

Fix the error in the code to correctly train the binary classification model.

TensorFlow
history = model.fit(X_train, y_train, epochs=[1], batch_size=32)
Drag options to blanks, or click blank then click option'
ANone
B'10'
C5
D'twenty'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing epochs as a string instead of an integer.
Passing None as epochs.
4fill in blank
hard

Fill both blanks to evaluate the model on test data and print accuracy.

TensorFlow
loss, [1] = model.evaluate(X_test, y_test)
print('Test [2]:', [1])
Drag options to blanks, or click blank then click option'
Aaccuracy
Bloss
Dscore
Attempts:
3 left
💡 Hint
Common Mistakes
Confusing loss and accuracy variables.
Printing the wrong variable.
5fill in blank
hard

Fill all three blanks to predict classes for new data and convert probabilities to binary labels.

TensorFlow
predictions = model.predict([1])
binary_predictions = (predictions [2] 0.5).astype([3])
Drag options to blanks, or click blank then click option'
AX_new
B>
Cint
DX_test
Attempts:
3 left
💡 Hint
Common Mistakes
Using test data instead of new data for prediction.
Using wrong comparison operator.
Not converting boolean array to integers.