0PricingLogin
Data Science Academy · Lesson

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_split

Four 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

  1. Why You Hold Out a Test Set
  2. train_test_split Done Right
  3. K-Fold Cross-Validation
  4. Stop Data Leakage Before It Starts
← Back to Data Science Academy