Challenge - 5 Problems
Model Compilation Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of model training metrics
Consider the following TensorFlow model compilation and training code snippet. What will be the printed output for the training accuracy after the first epoch?
TensorFlow
import tensorflow as tf import numpy as np model = tf.keras.Sequential([ tf.keras.layers.Dense(1, input_shape=(2,), activation='sigmoid') ]) model.compile(optimizer='sgd', loss='binary_crossentropy', metrics=['accuracy']) # Dummy data x_train = np.array([[0,0],[0,1],[1,0],[1,1]]) y_train = np.array([0,1,1,0]) history = model.fit(x_train, y_train, epochs=1, verbose=0) print(f"Training accuracy: {history.history['accuracy'][0]:.2f}")
Attempts:
2 left
💡 Hint
Think about the model's initial random weights and the simple dataset.
✗ Incorrect
With random initial weights and only one epoch, the model is unlikely to perfectly classify all samples, so accuracy around 0.5 is expected.
❓ Model Choice
intermediate1:30remaining
Choosing the correct loss function for multi-class classification
You want to compile a TensorFlow model to classify images into 5 categories. The labels are one-hot encoded vectors. Which loss function should you choose?
Attempts:
2 left
💡 Hint
One-hot encoded labels require a specific crossentropy loss.
✗ Incorrect
CategoricalCrossentropy is used when labels are one-hot encoded. SparseCategoricalCrossentropy is for integer labels.
❓ Hyperparameter
advanced1:30remaining
Effect of optimizer choice on training speed
You compile two identical models with the same architecture and loss but different optimizers: Adam and SGD. Which statement about their training behavior is generally true?
Attempts:
2 left
💡 Hint
Think about how Adam adjusts learning rates automatically.
✗ Incorrect
Adam optimizer adapts learning rates per parameter and often converges faster than vanilla SGD.
❓ Metrics
advanced2:00remaining
Interpreting multiple metrics in model.compile
If you compile a model with metrics=['accuracy', 'precision', 'recall'], what will be the output after training?
Attempts:
2 left
💡 Hint
TensorFlow supports standard metrics such as 'precision' and 'recall'.
✗ Incorrect
TensorFlow recognizes 'precision' and 'recall' as valid metrics and tracks them along with accuracy.
🔧 Debug
expert2:30remaining
Identifying the cause of a metric reporting error
You compile a TensorFlow model with metrics=['accuracy'] but during training, you get this error: "ValueError: Shapes (None, 1) and (None, 10) are incompatible". What is the most likely cause?
Attempts:
2 left
💡 Hint
Check the shapes of model outputs and labels carefully.
✗ Incorrect
This error usually means the model predicts a shape different from the labels, causing metric calculation to fail.