Problem 3: Stratified Split for Imbalanced Classes
Easypython
Learn the Concept: Train-Test SplitProblem Description
Write a Python program that performs a stratified train-test split on an imbalanced binary classification dataset, and prints the class distribution in both the training and test sets to confirm proportions were preserved.
Input
A dataset with an imbalanced binary label column.
Output
The class distribution in both the training and test sets.
Constraints
- The dataset should have a clear class imbalance (e.g., 90/10).
Example Input
texty with 90 zeros and 10 ones
Example Output
textTrain distribution: [72 8] Test distribution: [18 2]
Concepts Covered
stratify=y, np.bincount().
Related Problems
- Problem 1: Basic Train-Test SplitEasy · pythonSolve Problem
- Problem 2: Reproducible Split with random_stateEasy · pythonSolve Problem
- Problem 4: Split Then Scale CorrectlyEasy · pythonSolve Problem