0
0
TensorFlowml~20 mins

Prediction and evaluation in TensorFlow - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Prediction and Evaluation Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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)
A(1, 10)
B(28, 28, 10)
C(10, 10)
D(10, 28, 28)
Attempts:
2 left
💡 Hint
The model outputs one prediction vector per input image.
Metrics
intermediate
1:30remaining
Correct metric for binary classification
Which TensorFlow metric is most appropriate to evaluate a binary classification model's accuracy during training?
Atf.keras.metrics.MeanSquaredError()
Btf.keras.metrics.CategoricalAccuracy()
Ctf.keras.metrics.TopKCategoricalAccuracy(k=3)
Dtf.keras.metrics.BinaryAccuracy()
Attempts:
2 left
💡 Hint
Binary classification means two classes only.
Model Choice
advanced
2: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?
ADense(5, activation='softmax')
BDense(1, activation='sigmoid')
CDense(5, activation='sigmoid')
DDense(1, activation='softmax')
Attempts:
2 left
💡 Hint
Softmax outputs probabilities for multiple classes.
🔧 Debug
advanced
1: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}")
ANo error, prints loss and accuracy correctly
BValueError because y_test shape does not match model output
CTypeError because model.evaluate returns a dictionary, not tuple
DNameError because model is not defined
Attempts:
2 left
💡 Hint
Assume model and data are correctly defined and compatible.
🧠 Conceptual
expert
2: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?
ASmaller batch sizes always produce higher accuracy values
BBatch size does not affect final accuracy or loss values, only evaluation speed
CLarger batch sizes cause the model to overfit during evaluation
DChanging batch size changes the model weights and thus metrics
Attempts:
2 left
💡 Hint
Evaluation does not update model weights.