Challenge - 5 Problems
Validation Split Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the size of the validation set?
Given the code below, what is the number of samples in the validation set?
TensorFlow
import tensorflow as tf from tensorflow.keras import layers (x_train, y_train), _ = tf.keras.datasets.mnist.load_data() model = tf.keras.Sequential([ layers.Flatten(input_shape=(28, 28)), layers.Dense(10, activation='softmax') ]) history = model.fit(x_train, y_train, epochs=1, batch_size=32, validation_split=0.2)
Attempts:
2 left
💡 Hint
The MNIST training set has 60,000 samples. Validation split 0.2 means 20% of training data is used for validation.
✗ Incorrect
The training data has 60,000 samples. 20% of 60,000 is 12,000, so the validation set size is 12,000 samples.
❓ Model Choice
intermediate1:30remaining
Which validation_split value splits 25% of data for validation?
You want to reserve exactly 25% of your training data for validation during model.fit. Which validation_split value should you use?
Attempts:
2 left
💡 Hint
validation_split is the fraction of training data used for validation.
✗ Incorrect
validation_split=0.25 means 25% of the training data is used for validation.
❓ Hyperparameter
advanced1:30remaining
What happens if validation_split is set to 0.0?
In TensorFlow's model.fit, what is the effect of setting validation_split=0.0?
Attempts:
2 left
💡 Hint
validation_split controls the fraction of data reserved for validation.
✗ Incorrect
Setting validation_split=0.0 means no data is reserved for validation, so training uses all data.
🔧 Debug
advanced2:00remaining
Why does validation_split not work with a tf.data.Dataset?
Consider this code:
import tensorflow as tf
train_ds = tf.data.Dataset.from_tensor_slices((x_train, y_train))
model.fit(train_ds, epochs=3, validation_split=0.2)
Why does this raise an error?
Attempts:
2 left
💡 Hint
Check the data type compatibility of validation_split parameter.
✗ Incorrect
validation_split works only when input data is a NumPy array or tensor, not a tf.data.Dataset object.
🧠 Conceptual
expert2:30remaining
Why is validation_split applied before shuffling in model.fit?
In TensorFlow's model.fit, the validation_split is applied before shuffling the training data. What is the main reason for this behavior?
Attempts:
2 left
💡 Hint
Think about consistency of validation data across epochs.
✗ Incorrect
Applying validation_split before shuffling ensures the validation set is always the same fixed subset, providing consistent evaluation.