What leakage occurs if PCA is fitted on the entire dataset before cross-validation splitting?

Quick Overview

Asks what information leaks into cross-validation when PCA is fitted on the full dataset before the data is split into folds. Tests understanding of preprocessing leakage, how it affects cross-validation scores and model selection, and how to structure the workflow to avoid it.

What leakage occurs if PCA is fitted on the entire dataset before cross-validation splitting?

Role: Machine Learning Engineer

Category: Machine Learning

Difficulty: medium

Interview Round: Other

What leakage occurs if PCA is fitted on the entire dataset before cross-validation splitting? Suppose the features are standardized and projected with PCA using all rows, and k-fold cross-validation is then run on the projected data. ```hint What PCA estimates List every quantity PCA computes from the data it is fitted on, then ask which rows contributed to each one. ``` ```hint What CV simulates Think about what each validation fold is supposed to stand in for, and whether it still does once it has shaped the preprocessing. ``` ### What a Strong Answer Covers - Each quantity the scaler and PCA estimate from the data, and how validation rows reach it - What happens to the cross-validation score and how that affects model selection and tuning - When the leak is small and when it is large (sample size, dimensionality relative to rows, shift between folds) - How to change the workflow so cross-validation stays honest, including how the component count is chosen ### Follow-up Questions - Would supervised feature selection fitted on the full dataset cause the same problem, and would it be worse? - How do you choose `n_components` without leaking and still get an unbiased estimate of the tuned pipeline's performance? - If you have a large unlabeled pool from the same distribution, is fitting PCA on that pool plus the training rows still leakage? - How would you measure the size of this leak on a real dataset?

Overview: Asks what information leaks into cross-validation when PCA is fitted on the full dataset before the data is split into folds. Tests understanding of preprocessing leakage, how it affects cross-validation scores and model selection, and how to structure the workflow to avoid it.

PracHub logo
General
Nov 24, 2026
mediumMachine Learning EngineerOtherMachine Learning
0
0

What leakage occurs if PCA is fitted on the entire dataset before cross-validation splitting?

Suppose the features are standardized and projected with PCA using all rows, and k-fold cross-validation is then run on the projected data.

What a Strong Answer Covers Guidance

  • Each quantity the scaler and PCA estimate from the data, and how validation rows reach it
  • What happens to the cross-validation score and how that affects model selection and tuning
  • When the leak is small and when it is large (sample size, dimensionality relative to rows, shift between folds)
  • How to change the workflow so cross-validation stays honest, including how the component count is chosen

Follow-up Questions Guidance

  • Would supervised feature selection fitted on the full dataset cause the same problem, and would it be worse?
  • How do you choose n_components without leaking and still get an unbiased estimate of the tuned pipeline's performance?
  • If you have a large unlabeled pool from the same distribution, is fitting PCA on that pool plus the training rows still leakage?
  • How would you measure the size of this leak on a real dataset?