Principal component analysis (PCA) reduces dimensionality while preserving as much variance as possible. It combines correlated features into fewer, independent principal components that retain the most important information. section 9.2.5
Apply PCA through a repeatable preparation and selection workflow:
- Split labeled data into training and testing subsets, beginning with an 80–20 split, and check class balance. section 9.2.5
- Scale training features to mean zero and standard deviation one with StandardScaler before applying PCA. section 9.2.5
Four-component projection
Setting PCA(n_components=4) transforms X_train_scaled into X_train_pca with columns PC1 through PC4; PC1 and PC2 or PC3 and PC4 can then be plotted by class.









