3.P2 Splitting Train/Test with train_test_split
[video] /api/lesson-media/videos/9b417aa2-5e9f-4ae3-a9db-2a3b7f03f372-1794878469714-ac6951e618e19b1d.mp4
[markdown] content available only on the platform
[markdown] content available only on the platform
Flashcards · 3.P2 Splitting Train/Test with train_test_split
train_test_split() — scikit-learn function that randomly splits features and labels into training and test sets.
train_test_split(x, y, test_size=0.2, random_state=1009)
test_size — The proportion (or number) of rows reserved for the test set.
test_size=0.2 -> 20% test, 80% train
Return order — train_test_split returns x_train, x_test, y_train, y_test, always in this order.
x_train, x_test, y_train, y_test = train_test_split(x, y)
Training set — The rows the model learns from.
614 rows of diabetes.csv
Test set — Rows held back to evaluate the model on data it has never seen.
154 rows of diabetes.csv
y_train — The labels used together with x_train to train the model.
model.fit(x_train, y_train)
random_state — A seed that fixes the random split, so every run produces the same training and test sets.
random_state=1009
Fair benchmarking — Comparing models on exactly the same test set so score differences reflect the models.
80% vs 81% only comparable on the same test set.
