train_test_split Done Right
Stratify, random_state, and ratios.
One Helper, Two Sets
The function train_test_split takes your features and target and hands back train and test pieces in one tidy call.
from sklearn.model_selection import train_test_splitFour Things Come Back
It returns four objects in a fixed order: train features, test features, train target, test target. Unpack them carefully so each lands in the right name.
X_train, X_test, y_train, y_test = train_test_split(X, y)All lessons in this course
- Why You Hold Out a Test Set
- train_test_split Done Right
- K-Fold Cross-Validation
- Stop Data Leakage Before It Starts