Back to the lessonPreparing the printout…

Fundamental of Machine Learning · Module 3: Model Evaluation and Optimization

3.P3 random_state and Reproducibility

[video] /api/lesson-media/videos/9b417aa2-5e9f-4ae3-a9db-2a3b7f03f372-1794878470118-1a5e493fadb4b4e2.mp4

[markdown] content available only on the platform

[markdown] content available only on the platform

Flashcards · 3.P3 random_state and Reproducibility

random_state — A seed that fixes random operations so they give the same result on every run.

train_test_split(x, y, random_state=1009)

Reproducibility — Getting exactly the same results when an experiment is run again.

Same seed -> same x_train and x_test.

DataFrame index — The row labels of a DataFrame; after a random split they show which original rows were picked.

x_train.index[:5] -> 498, 705, 36, 199, 309

Random split — Assigning rows to train and test by chance; without a seed it changes on every call.

Commenting out random_state gives new indices each run.

Fixed test set — A test set that stays identical across experiments, so score differences reflect model changes.

Keep random_state=1009 for all runs.

Same-exam analogy — Students must take the same test to be compared; models must be evaluated on the same test set.

9 on test A vs 8 on test B proves nothing.

index.equals() — pandas method that checks whether two indexes contain the same labels in the same order.

a.index.equals(b.index) -> True

Fundamental of Machine Learning · 3.P3 random_state and Reproducibility · printed on November 21, 2026