Challenge - 5 Problems
Prediction and Evaluation Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of model prediction shape
Given a TensorFlow model trained on images of shape (28, 28, 1), what is the shape of the output predictions for a batch of 10 images?
TensorFlow
import tensorflow as tf import numpy as np model = tf.keras.Sequential([ tf.keras.layers.Flatten(input_shape=(28, 28, 1)), tf.keras.layers.Dense(10, activation='softmax') ]) batch = np.random.rand(10, 28, 28, 1).astype(np.float32) predictions = model(batch) print(predictions.shape)
Attempts:
2 left
💡 Hint
The model outputs one prediction vector per input image.
✗ Incorrect
The model outputs a vector of length 10 (number of classes) for each of the 10 input images, so the output shape is (10, 10).
❓ Metrics
intermediate1:30remaining
Correct metric for binary classification
Which TensorFlow metric is most appropriate to evaluate a binary classification model's accuracy during training?
Attempts:
2 left
💡 Hint
Binary classification means two classes only.
✗ Incorrect
BinaryAccuracy is designed to measure accuracy for two-class problems, while CategoricalAccuracy is for multi-class classification.
❓ Model Choice
advanced2:00remaining
Best model output layer for multi-class classification
You want to build a TensorFlow model to classify images into 5 categories. Which output layer configuration is best?
Attempts:
2 left
💡 Hint
Softmax outputs probabilities for multiple classes.
✗ Incorrect
For multi-class classification, a Dense layer with units equal to number of classes and softmax activation is standard.
🔧 Debug
advanced1:30remaining
Identify the error in evaluation code
What error will this TensorFlow code raise when evaluating a model on test data?
TensorFlow
loss, accuracy = model.evaluate(x_test, y_test) print(f"Loss: {loss}, Accuracy: {accuracy}")
Attempts:
2 left
💡 Hint
Assume model and data are correctly defined and compatible.
✗ Incorrect
model.evaluate returns loss and metrics as a tuple, so unpacking into loss and accuracy works if accuracy metric was compiled.
🧠 Conceptual
expert2:30remaining
Effect of batch size on evaluation metrics
How does changing the batch size during model evaluation affect the reported accuracy and loss metrics in TensorFlow?
Attempts:
2 left
💡 Hint
Evaluation does not update model weights.
✗ Incorrect
Evaluation metrics are computed over the whole dataset and are independent of batch size; batch size only affects computation speed and memory use.