Train, validation and test
Hold out data so your score means something.
What you will be able to do
- Split before scaling or imputing.
- Use a fixed random_state for reproducibility.
- Stratify classification splits.
- Keep a final untouched test set.
In plain English
The test set estimates performance on unseen data. The validation set is for tuning. Never touch the test set until the end, and split before fitting any preprocessing step.
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(
X, y, test_size=0.2, random_state=42, stratify=y
)
print(len(X_train), len(X_test))Your turn
EasyMake a stratified split
Split X and y with a 20% test size and stratification.
PYTHON · starter
train_test_split(X, y, test_size=0.2)Check your understanding before moving on.
Knowledge checkQuestion 1
Why split before preprocessing?
Select an answer to continue
Study tools
Make it yours.
Keep a private note for this lesson, then turn the key ideas into flashcards you can revisit.
Sign in to save notes and flashcards.Both are private to your account and stay with your progress.
Sign inFinished reading?
Lock in what you just learned.
0%
Mark this lesson complete to save your place and move one step closer to the certificate.