How would you monitor and refit a PCA transform in production when the input data distribution drifts?
Role: Machine Learning Engineer
Category: Machine Learning
Difficulty: medium
Interview Round: Other
How would you monitor and refit a PCA transform in production when the input data distribution drifts?
Assume a fitted scaler and PCA sit in front of a downstream model, and the PCA was fit once on a historical training window.
```hint Use the frozen transform itself
Besides watching the raw inputs, think about what the fitted PCA lets you compute on each new row that tells you whether the learned subspace still describes it.
```
```hint Think about what depends on the components
Ask what happens to everything downstream if you refit PCA and the components come back in a different order or with flipped signs.
```
### Clarifying Questions to Ask
- Are the PCA outputs consumed only by the downstream model, or also stored as features or shown on dashboards?
- Does data arrive in batches or as a continuous stream, and how fast is the distribution expected to change?
- Are labels or other downstream performance signals available, and with what delay?
### What a Strong Answer Covers
- Signals for drift in the inputs, and signals that show whether the frozen PCA still fits new data
- How alert thresholds are set and what counts as drift that justifies a refit
- Which pipeline pieces must change together on a refit, and why
- How to handle consumers of the raw PCA outputs when components reorder or flip sign
- A safe rollout path with offline validation, shadow or canary deployment and rollback
### Follow-up Questions
- Reconstruction error stays flat but Hotelling's T² rises sharply. What does that tell you, and what would you do?
- How would you compute the principal angles between the production subspace and one fit on recent data?
- When is `IncrementalPCA` a better choice than periodic full refits, and what does it cost you?
- How would you set the number of components again after a refit, and what if it changes?
Overview: Asks how to detect when a production PCA transform no longer fits drifting input data and how to refit it safely. Tests reconstruction error, Hotelling's T², subspace angles, refit triggers, and versioning the scaler, PCA and downstream model together.