A train-test split partitions labeled data into separate subsets: one trains a supervised machine-learning model, while the other evaluates its performance. section 9.2.5
Use a practical split workflow:
- Start with an 80-20 split, assigning 80% of the data to training and 20% to testing. section 9.2.5
- Check that class distributions remain approximately balanced in both subsets. section 9.2.5
- Continue preprocessing with feature scaling before applying PCA to the training data. section 9.2.5
Splitting a labeled data set
Separate feature columns from the class label, then call scikit-learn’s train_test_split with test_size=0.2 and random_state=42 to produce X_train, X_test, y_train, and y_test. section 9.2.5
Listing 9.12 Splitting df_orig_selected
from sklearn.model_selection import train_test_split #1
X = df_orig_selected.drop(‚class', axis=1) #2
y = df_orig_selected['class'] #3
X_train, X_test, y_train, y_test = \
train_test_split(X, y, test_size=0.2, random_state=42 #4
Inspect the concrete Python split used to create training and testing features and labels. section 9.2.5




















