Centering data
Centering subtracts the training-sample mean of each feature from that feature’s values.
On this page 9 sections
01PCA looks for variation around a typical observation#
PCA looks for variation around a typical observation. Centering moves that typical observation to the origin: subtract each feature’s training mean from every value of that feature. Differences from the mean then describe variation, rather than the arbitrary location of the original zero.
Suppose two sensors have mean readings 10 and 100. A reading becomes : the first is 2 above its typical value and the second is 3 below. Subtracting one grand average would mix the meanings of the sensors.
Centering subtracts one mean per feature. With observations as rows, compute the mean down each column. Each centered value keeps its original units.
Training rows and have means . Subtract them from both rows: and .
Place observations in rows and features in columns. For rows and , the column means are . Subtract the same pair from both rows to obtain and . Each centered column sums to zero. This is a useful check, not a reason to center each row separately.
Training observation rows: ; . Give centered rows.
Show answer and explanation
Subtract feature means .
02Each centered training column sums to zero#
Each centered training column sums to zero. Subtracting a separate mean across each row answers a different question. Dividing by standard deviation is scaling; it is not part of centering.
Training observation rows: ; . Claimed centered rows: ; . Repair.
Show answer and explanation
Subtract feature means .
03Keep training means fixed for new data#
Keep training means fixed for new data. Training rows and give means . A new row becomes . Do not let that new row change the training means.
Training rows: ; . New row . Center the new row.
Show answer and explanation
Use training means .
04When transforming a new observation, reuse the means learned from the training set#
When transforming a new observation, reuse the means learned from the training set. Recomputing them on the test set changes the transformation and lets evaluation data influence the procedure. Centering subtracts means; standardization additionally rescales features and can change PCA directions.
Center columns with training means. Reuse those means for new data; keep the original units.
- Center each data feature using training-sample means.
Further questions
Does centering make every feature equally variable?
Sources & further reading
- [1]Cornell CS4780, Principal component analysis ↗Cornell CS4780 · Book
- [2]scikit-learn, Common pitfalls: inconsistent preprocessing and data leakage ↗scikit-learn · Book