Choose the best reason why splitting data into training and testing sets is important.
Think about why we want to check the model's ability beyond the data it learned from.
We split data to test if the model can generalize to new, unseen data, not just memorize the training data.
What will be the output sizes of training and testing sets after this code runs?
from sklearn.model_selection import train_test_split X = list(range(100)) y = [x * 2 for x in X] X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.25, random_state=42) print(len(X_train), len(X_test))
Test size is 0.25, so test set should be 25% of 100.
With test_size=0.25, 25% of 100 is 25 for testing, leaving 75 for training.
Which test_size value is best if you want to maximize training data but still have a reliable test set?
Think about a balance between enough training data and enough test data.
A test_size of 0.2 means 20% test data and 80% training data, a common good balance.
What error will this code raise?
from sklearn.model_selection import train_test_split X = [1, 2, 3] y = [4, 5] X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.33)
Check if X and y have the same length.
X and y must have the same number of samples; here they differ, causing a ValueError.
You have a classification dataset with very imbalanced classes. Which train-test split approach is best to keep class proportions consistent?
Think about how to keep class distribution similar in train and test sets.
Using stratify ensures the train and test sets have the same class proportions, important for imbalanced data.
