0
0
TensorFlowml~20 mins

model.fit() training loop in TensorFlow - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Model.fit() Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of model.fit() training metrics
What will be the output of the training metrics after running this code snippet?
TensorFlow
import tensorflow as tf
import numpy as np

# Simple dataset
x = np.array([[0.], [1.], [2.], [3.], [4.], [5.]], dtype=float)
y = np.array([[0.], [2.], [4.], [6.], [8.], [10.]], dtype=float)

# Simple linear model
model = tf.keras.Sequential([tf.keras.layers.Dense(1, input_shape=(1,))])
model.compile(optimizer='sgd', loss='mse', metrics=['mae'])

history = model.fit(x, y, epochs=3, verbose=0)

print(history.history)
A{"loss": [4.0, 0.25, 0.0625], "mae": [2.0, 1.0, 0.5]}
B{"loss": [4.0, 0.5, 0.125], "mae": [2.0, 1.0, 0.5]}
C{"loss": [4.0, 0.25, 0.0625], "mae": [1.5, 0.5, 0.25]}
D{"loss": [4.0, 0.5, 0.125], "mae": [1.5, 0.5, 0.25]}
Attempts:
2 left
💡 Hint
Look at how loss and mae decrease over epochs in a simple linear regression with SGD optimizer.
🧠 Conceptual
intermediate
1:30remaining
Understanding batch size effect in model.fit()
Which statement correctly describes the effect of batch size in the model.fit() training loop?
AA larger batch size uses more memory but can lead to more stable gradient estimates during training.
BA smaller batch size always leads to faster training and better model accuracy.
CBatch size does not affect training speed or model performance.
DBatch size only affects the number of epochs, not the training steps per epoch.
Attempts:
2 left
💡 Hint
Think about how batch size influences memory use and gradient calculation.
Hyperparameter
advanced
1:30remaining
Choosing the right number of epochs in model.fit()
If a model is overfitting the training data during model.fit(), which adjustment is most appropriate?
ADecrease the number of epochs to stop training earlier.
BIncrease the batch size to reduce overfitting.
CIncrease the number of epochs to let the model learn more.
DUse a higher learning rate to speed up training.
Attempts:
2 left
💡 Hint
Overfitting means the model learns too much from training data and performs worse on new data.
🔧 Debug
advanced
1:30remaining
Identifying error in model.fit() usage
What error will this code raise when calling model.fit()?
TensorFlow
import tensorflow as tf

model = tf.keras.Sequential([tf.keras.layers.Dense(1)])
model.compile(optimizer='adam', loss='mse')

# Missing input data
model.fit(epochs=5)
ANo error, training runs with default data
BValueError: Data provided to model is empty
CRuntimeError: Model not compiled
DTypeError: fit() missing 1 required positional argument: 'x'
Attempts:
2 left
💡 Hint
Check the required arguments for model.fit()
Model Choice
expert
2:00remaining
Selecting model architecture for time series forecasting with model.fit()
You want to predict future values of a time series using model.fit(). Which model architecture is best suited for this task?
AA convolutional neural network (CNN) designed for image classification
BA simple feedforward neural network with Dense layers only
CA recurrent neural network (RNN) or LSTM model designed to handle sequences
DA clustering model like KMeans
Attempts:
2 left
💡 Hint
Time series data has order and depends on previous values.