Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to import the function that splits data into training and testing sets.
ML Python
from sklearn.model_selection import [1]
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect function names like 'train_test' or 'test_train_split'.
Forgetting to import from sklearn.model_selection.
✗ Incorrect
The correct function to split data into training and testing sets is 'train_test_split' from sklearn.model_selection.
2fill in blank
mediumComplete the code to split features X and labels y into training and testing sets with 30% test size.
ML Python
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=[1])Attempts:
3 left
💡 Hint
Common Mistakes
Using integers like 30 instead of 0.3.
Using very small numbers like 0.03 which means 3%.
✗ Incorrect
The test_size parameter expects a float between 0 and 1 representing the proportion of the dataset to include in the test split. 0.3 means 30%.
3fill in blank
hardFix the error in the code to correctly split data with a fixed random state for reproducibility.
ML Python
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.25, random_state=[1])
Attempts:
3 left
💡 Hint
Common Mistakes
Using a string like 'random' instead of an integer.
Using None which means no fixed seed.
✗ Incorrect
random_state should be an integer to ensure reproducible splits. 42 is a common choice.
4fill in blank
hardFill both blanks to split data with 20% test size and shuffle enabled.
ML Python
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=[1], shuffle=[2])
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0.8 for test_size which means 80% test data.
Setting shuffle to False which disables shuffling.
✗ Incorrect
test_size=0.2 means 20% test data, and shuffle=True means data is shuffled before splitting.
5fill in blank
hardFill all three blanks to split data with 25% test size, shuffle disabled, and random state 123.
ML Python
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=[1], shuffle=[2], random_state=[3])
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up True and False for shuffle.
Using a string instead of an integer for random_state.
Using 25 instead of 0.25 for test_size.
✗ Incorrect
test_size=0.25 means 25% test data, shuffle=False disables shuffling, and random_state=123 fixes the split for reproducibility.
