0
0
TensorFlowml~20 mins

Validation split in TensorFlow - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Validation Split Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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)
A12000
B10000
C20000
D6000
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.
Model Choice
intermediate
1: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?
A0.25
B0.75
C0.5
D0.2
Attempts:
2 left
💡 Hint
validation_split is the fraction of training data used for validation.
Hyperparameter
advanced
1: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?
AThe entire dataset is split equally between training and validation
BAll data is used as validation data
CAn error is raised because 0.0 is invalid
DNo validation data is used during training
Attempts:
2 left
💡 Hint
validation_split controls the fraction of data reserved for validation.
🔧 Debug
advanced
2: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?
Avalidation_split must be an integer, not a float
Btf.data.Dataset objects cannot be used for training
Cvalidation_split only works with NumPy arrays or tensors, not tf.data.Dataset
DThe batch size is missing, causing validation_split to fail
Attempts:
2 left
💡 Hint
Check the data type compatibility of validation_split parameter.
🧠 Conceptual
expert
2: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?
ATo speed up training by reducing shuffling overhead
BTo ensure the validation set is a fixed subset of the original data, not affected by shuffling
CTo shuffle the validation data separately from training data
DTo randomly assign samples to validation or training sets each epoch
Attempts:
2 left
💡 Hint
Think about consistency of validation data across epochs.