🎯 Train Test Split Playground

Explore sklearn's train_test_split() function interactively

⚙️ Parameters

Proportion of dataset in test set

Total number of samples

Percentage of samples in Class 0 (blue)

shuffle

Randomize data order

stratify

Preserve class ratios

Seed for reproducibility

Training Set (28 samples)

Class 0: 11 (39.3%)
Class 1: 17 (60.7%)

Test Set (12 samples)

Class 0: 5 (41.7%)
Class 1: 7 (58.3%)

📚 Key Concepts

🔀 Shuffling (shuffle=True)

When enabled, data is randomly reordered before splitting. This prevents order-dependent bias, especially if your data is sorted by time, category, or target value. The numbers show original indices - watch how they get mixed when shuffle is on!

📊 Stratification (stratify=y)

Preserves the class distribution in both train and test sets. Critical for imbalanced datasets! Notice how the class percentages stay similar between train and test when stratify is enabled. Without it, you might get unlucky splits with very different distributions.

🎲 Random State

Seeds the random number generator for reproducibility. Same random_state = same split every time. Change it to see different random splits. Essential for comparing model experiments fairly!

📏 Test Size

Fraction of data reserved for testing. Common values: 0.2-0.3. Larger test sets give better performance estimates but leave less data for training. It's a trade-off!