0
0
TensorFlowml~10 mins

Validation split in TensorFlow - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to split the data into training and validation sets using Keras model.fit.

TensorFlow
model.fit(x_train, y_train, epochs=10, batch_size=32, validation_split=[1])
Drag options to blanks, or click blank then click option'
ANone
B2
C20
D0.2
Attempts:
3 left
💡 Hint
Common Mistakes
Using an integer like 2 or 20 instead of a fraction.
Setting validation_split to None which disables validation.
2fill in blank
medium

Complete the code to create a validation set from training data using sklearn's train_test_split.

TensorFlow
from sklearn.model_selection import train_test_split
x_train, x_val, y_train, y_val = train_test_split(x, y, test_size=[1], random_state=42)
Drag options to blanks, or click blank then click option'
A10
B0.1
C0.5
DNone
Attempts:
3 left
💡 Hint
Common Mistakes
Using an integer like 10 instead of a fraction.
Setting test_size to None which causes an error.
3fill in blank
hard

Fix the error in the code to correctly use validation_split in model.fit.

TensorFlow
history = model.fit(x_train, y_train, epochs=5, validation_split=[1])
Drag options to blanks, or click blank then click option'
A0.2
BNone
C'0.2'
D20
Attempts:
3 left
💡 Hint
Common Mistakes
Passing validation_split as a string like '0.2'.
Passing an integer like 20 instead of a fraction.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps words to their lengths only if length is greater than 3.

TensorFlow
lengths = {word: [1] for word in words if len(word) [2] 3}
Drag options to blanks, or click blank then click option'
Alen(word)
B>
C<
Dword
Attempts:
3 left
💡 Hint
Common Mistakes
Using the word itself as the value instead of its length.
Using less than (<) instead of greater than (>) in the condition.
5fill in blank
hard

Fill all three blanks to create a filtered dictionary with uppercase keys, values, and a condition.

TensorFlow
result = [1]: [2] for k, v in data.items() if v [3] 0}
Drag options to blanks, or click blank then click option'
Ak.upper()
Bv
C>
Dk
Attempts:
3 left
💡 Hint
Common Mistakes
Using original keys without uppercase.
Using incorrect comparison operators like < or ==.