Challenge - 5 Problems
Model.fit() Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2: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)
Attempts:
2 left
💡 Hint
Look at how loss and mae decrease over epochs in a simple linear regression with SGD optimizer.
✗ Incorrect
The mean squared error (loss) and mean absolute error (mae) decrease as the model learns. The values in option B match typical outputs for this simple training.
🧠 Conceptual
intermediate1:30remaining
Understanding batch size effect in model.fit()
Which statement correctly describes the effect of batch size in the model.fit() training loop?
Attempts:
2 left
💡 Hint
Think about how batch size influences memory use and gradient calculation.
✗ Incorrect
Larger batch sizes use more memory but provide more stable gradient estimates, which can improve training stability. Smaller batches can be noisy but may generalize better.
❓ Hyperparameter
advanced1: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?
Attempts:
2 left
💡 Hint
Overfitting means the model learns too much from training data and performs worse on new data.
✗ Incorrect
Reducing epochs helps prevent the model from learning noise in the training data, which causes overfitting.
🔧 Debug
advanced1: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)
Attempts:
2 left
💡 Hint
Check the required arguments for model.fit()
✗ Incorrect
model.fit() requires input data 'x' and target 'y' unless using a dataset. Omitting 'x' causes a TypeError.
❓ Model Choice
expert2: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?
Attempts:
2 left
💡 Hint
Time series data has order and depends on previous values.
✗ Incorrect
RNNs and LSTMs are designed to process sequences and remember past information, making them ideal for time series forecasting.