Challenge - 5 Problems
Training History Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the final training accuracy after 3 epochs?
Consider this TensorFlow training code snippet. What is the final training accuracy printed after training for 3 epochs?
TensorFlow
import tensorflow as tf from tensorflow.keras import layers, models model = models.Sequential([ layers.Dense(10, activation='relu', input_shape=(5,)), layers.Dense(2, activation='softmax') ]) model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy']) import numpy as np x_train = np.random.random((100, 5)) y_train = np.random.randint(0, 2, 100) history = model.fit(x_train, y_train, epochs=3, verbose=0) final_acc = history.history['accuracy'][-1] print(round(final_acc, 2))
Attempts:
2 left
💡 Hint
Look at the last value in the 'accuracy' list from the history object.
✗ Incorrect
The model trains for 3 epochs and the accuracy improves from around 0.5 to about 0.85 by the last epoch.
🧠 Conceptual
intermediate1:30remaining
What does the 'history.history' dictionary contain?
After training a TensorFlow model, the 'history' object has an attribute 'history'. What does this dictionary store?
Attempts:
2 left
💡 Hint
Think about what changes after each epoch during training.
✗ Incorrect
The 'history.history' dictionary stores lists of values for each metric and loss recorded at the end of every epoch.
❓ Metrics
advanced1:30remaining
Which metric is best to monitor for classification accuracy during training?
You want to track how well your classification model predicts correct labels during training. Which metric should you monitor?
Attempts:
2 left
💡 Hint
Accuracy measures correct predictions as a percentage.
✗ Incorrect
Accuracy directly measures the proportion of correct predictions, making it ideal for classification tasks.
🔧 Debug
advanced2:30remaining
Why does this training history plot show a flat line?
You run this code to plot training accuracy but the graph is a flat line at 1.0. What is the likely cause?
import matplotlib.pyplot as plt
plt.plot(history.history['accuracy'])
plt.xlabel('Epoch')
plt.ylabel('Accuracy')
plt.show()
TensorFlow
import tensorflow as tf from tensorflow.keras import layers, models import numpy as np model = models.Sequential([ layers.Dense(10, activation='relu', input_shape=(5,)), layers.Dense(2, activation='softmax') ]) model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy']) x_train = np.random.random((100, 5)) y_train = np.zeros(100, dtype=int) # All labels are zero history = model.fit(x_train, y_train, epochs=5, verbose=0) import matplotlib.pyplot as plt plt.plot(history.history['accuracy']) plt.xlabel('Epoch') plt.ylabel('Accuracy') plt.show()
Attempts:
2 left
💡 Hint
Check the training labels and their diversity.
✗ Incorrect
Since all labels are zero, the model can easily predict the same class and accuracy remains constant at 1.0.
❓ Model Choice
expert3:00remaining
Which model architecture is best for visualizing training history of a time series prediction?
You want to train a model on time series data and visualize its training loss and accuracy. Which model architecture is most suitable?
Attempts:
2 left
💡 Hint
Time series data has order and sequence information.
✗ Incorrect
RNNs with LSTM layers are designed to handle sequential data like time series and can be trained over epochs to visualize training history.