Can we replace hundreds of correlated features with a smaller representation?
Separate variance preservation from predictive usefulness, and reason about scaling and reconstruction.
01. State the optimization target
Principal component analysis constructs orthogonal directions that capture variance in centered data. Keeping the first few directions gives a lower-dimensional linear representation. This is useful for compression or diagnosing redundant measurements, but the directions do not know the prediction target.
Imagine two sensors measuring nearly the same temperature plus a low-variance alarm signal. A compressed representation may retain the sensor variation and discard the alarm even if the alarm is the most useful predictor. Evaluate the downstream model, not just the amount of variance retained.
02. Work through the geometry
Consider centered observations (1,1), (-1,-1), (2,2), and (-2,-2). They lie on one line. The unit direction (1,1)/sqrt(2) captures all their variance. Projecting (2,2) gives 2sqrt(2); multiplying that scalar by the direction reconstructs (2,2) exactly. The perpendicular direction has zero variance.
Real data rarely has exact redundancy. Dropping a direction introduces reconstruction error. An explained-variance ratio describes the retained variance relative to total variance for the fitted data; it is not a percentage of prediction accuracy.
03. Keep preprocessing inside the split
Fit centering, optional scaling, and PCA on the training partition. Apply those fitted transformations to validation and test data. If the full dataset determines the axes, validation information has influenced the representation. In cross-validation, repeat the fitting within each fold.
Scaling is a modeling choice. Measurements in dollars can dominate measurements in small units. Standardization makes their variances comparable but may amplify a noisy feature. Compare an uncompressed baseline, a standardized model, and a compressed model under the same validation protocol.
04. Defend a production decision
Suppose reducing 500 inputs to 40 components saves memory but adds a dense matrix multiplication on every request. Measure total latency including preprocessing and feature retrieval. Compression alone does not guarantee a faster serving path.
Version the mean vector, scaling parameters, components, and predictor as one artifact. Individual component signs can flip across fits without changing the represented subspace; interpret the full transformation instead of declaring drift from a sign change. Follow-up: for sparse text counts, investigate truncated SVD because centering can destroy sparsity.
Practice the follow-up
Construct a dataset where a low-variance feature predicts the target perfectly. Explain why retaining 99% of input variance could still hurt.
Connect this to validation strategies.
Sources & further reading
scikit-learn: decomposition. The interview scenario, calculations, and proposed design choices are illustrative.
Continue your preparation
Choose a connected learning path or browse more ML fundamentals questions. Read our editorial method and attribution policy.