scikit-learn 1 · Data and splitting
Split into train and test sets
Hold out 20% of the data for testing. stratify keeps class proportions, and random_state makes it repeatable.
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, stratify=y, random_state=42)
Official scikit-learn 1 documentation