0
0
TensorFlowml~20 mins

Training history and visualization in TensorFlow - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Training History Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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))
A0.75
B0.99
C0.50
D0.85
Attempts:
2 left
💡 Hint
Look at the last value in the 'accuracy' list from the history object.
🧠 Conceptual
intermediate
1: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?
AThe compiled model configuration
BThe model's weights after training
CLists of metric values and loss for each epoch during training
DThe training dataset used for fitting the model
Attempts:
2 left
💡 Hint
Think about what changes after each epoch during training.
Metrics
advanced
1: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?
Aaccuracy
Bmean_squared_error
Ccategorical_crossentropy
Dmean_absolute_error
Attempts:
2 left
💡 Hint
Accuracy measures correct predictions as a percentage.
🔧 Debug
advanced
2: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()
AThe model did not compile correctly
BThe training labels have no variation, so accuracy stays constant
CThe plot command is missing plt.show()
DThe accuracy metric is not supported for this model
Attempts:
2 left
💡 Hint
Check the training labels and their diversity.
Model Choice
expert
3: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?
AA recurrent neural network (RNN) with LSTM layers
BA simple dense neural network with one hidden layer
CA convolutional neural network (CNN) designed for image data
DA linear regression model without epochs
Attempts:
2 left
💡 Hint
Time series data has order and sequence information.