Challenge - 5 Problems
Binary Classification Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of a simple binary classification model training
Consider the following TensorFlow code that trains a binary classification model on dummy data. What will be the printed training accuracy after 5 epochs?
TensorFlow
import tensorflow as tf import numpy as np # Create dummy data x_train = np.random.random((100, 10)) y_train = np.random.randint(2, size=(100, 1)) # Build a simple model model = tf.keras.Sequential([ tf.keras.layers.Dense(8, activation='relu', input_shape=(10,)), tf.keras.layers.Dense(1, activation='sigmoid') ]) model.compile(optimizer='adam', loss='binary_crossentropy', metrics=['accuracy']) history = model.fit(x_train, y_train, epochs=5, batch_size=10, verbose=0) print(f"Training accuracy after 5 epochs: {history.history['accuracy'][-1]:.2f}")
Attempts:
2 left
💡 Hint
The data is random and labels are random, so the model cannot learn meaningful patterns.
✗ Incorrect
Since the input data and labels are random, the model cannot find patterns to improve accuracy. The accuracy will stay close to random guessing, about 50%.
❓ Model Choice
intermediate1:30remaining
Choosing the correct output layer for binary classification
Which output layer configuration is correct for a binary classification model in TensorFlow?
Attempts:
2 left
💡 Hint
Binary classification usually uses one output neuron with a sigmoid activation.
✗ Incorrect
For binary classification, the output layer should have one neuron with sigmoid activation to output a probability between 0 and 1.
❓ Hyperparameter
advanced1:30remaining
Best loss function for binary classification
Which loss function is most appropriate when training a binary classification model with a sigmoid output in TensorFlow?
Attempts:
2 left
💡 Hint
Binary classification with sigmoid output requires a loss that handles probabilities for two classes.
✗ Incorrect
BinaryCrossentropy is designed for binary classification problems with sigmoid outputs, measuring the difference between true labels and predicted probabilities.
❓ Metrics
advanced1:30remaining
Interpreting model accuracy on imbalanced binary data
A binary classification model is trained on a dataset where 95% of samples belong to class 0 and 5% to class 1. The model always predicts class 0. What accuracy will the model achieve?
Attempts:
2 left
💡 Hint
Accuracy counts how many predictions match true labels.
✗ Incorrect
Since 95% of samples are class 0, always predicting class 0 yields 95% accuracy, but the model fails to detect class 1.
🔧 Debug
expert2:00remaining
Identifying the error in binary classification model compilation
What error will this TensorFlow code raise when compiling a binary classification model?
TensorFlow
import tensorflow as tf model = tf.keras.Sequential([ tf.keras.layers.Dense(16, activation='relu', input_shape=(20,)), tf.keras.layers.Dense(1, activation='sigmoid') ]) model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy'])
Attempts:
2 left
💡 Hint
Check if the loss function matches the output layer and label format.
✗ Incorrect
Using 'categorical_crossentropy' with a single sigmoid output neuron causes a shape mismatch error because categorical_crossentropy expects one-hot encoded labels and multiple output neurons.