Challenge - 5 Problems
Model Training Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediateWhat is the output of the training accuracy after 1 epoch?
Consider this TensorFlow model training snippet. What will be the printed training accuracy after 1 epoch?
TensorFlow
import tensorflow as tf import numpy as np # Create dummy data x_train = np.random.random((100, 10)) y_train = np.random.randint(0, 2, 100) # Build simple model model = tf.keras.Sequential([ tf.keras.layers.Dense(5, 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=1, batch_size=10, verbose=0) print(f"Training accuracy: {history.history['accuracy'][0]:.2f}")
Attempts:
2 left
💡 Hint
The model is untrained and data is random, so accuracy will be close to random guessing.
✗ Incorrect
Since the data and labels are random, the model cannot learn meaningful patterns in one epoch. The accuracy will be close to random guessing, which is about 50% for binary classification.
❓ Model Choice
intermediateWhich optimizer is best for fast convergence on a small dataset?
You want to train a small neural network on a small dataset quickly. Which optimizer should you choose for faster convergence?
Attempts:
2 left
💡 Hint
Think about which optimizer adapts learning rates and works well with small datasets.
✗ Incorrect
Adam optimizer adapts learning rates for each parameter and usually converges faster on small datasets compared to vanilla SGD or other optimizers.
❓ Hyperparameter
advancedWhat happens if you set batch_size larger than training data size?
In TensorFlow model training, what is the effect of setting batch_size larger than the total number of training samples?
Attempts:
2 left
💡 Hint
Think about how batch size controls how many samples are processed before updating weights.
✗ Incorrect
If batch_size is larger than the dataset size, TensorFlow uses the whole dataset as a single batch for each epoch.
❓ Metrics
advancedWhich metric is best for imbalanced binary classification?
You train a binary classifier on a dataset where one class is much rarer than the other. Which metric should you monitor during training to better evaluate model performance?
Attempts:
2 left
💡 Hint
Consider a metric that balances precision and recall for imbalanced data.
✗ Incorrect
F1-score balances precision and recall, making it a better metric than accuracy alone for imbalanced datasets.
🔧 Debug
expertWhy does this TensorFlow training code raise a ValueError?
Examine the code below. Why does it raise a ValueError during model.fit()?
TensorFlow
import tensorflow as tf import numpy as np x_train = np.random.random((50, 20)) y_train = np.random.randint(0, 3, 50) model = tf.keras.Sequential([ tf.keras.layers.Dense(10, activation='relu', input_shape=(20,)), tf.keras.layers.Dense(3, activation='softmax') ]) model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy']) model.fit(x_train, y_train, epochs=5)
Attempts:
2 left
💡 Hint
Check the output layer units and activation for multi-class classification.
✗ Incorrect
Softmax activation expects the output layer to have as many units as classes. Here, output layer has 1 unit but labels have 3 classes, causing a ValueError.
