The reading shows a three-dimensional cloud compressed into two coordinates. We’ll use that same cloud, fit PCA ourselves, and check what changes when we retain fewer directions.
First, center the columns. The directions must be learned from the centered data, and new observations must use those same means and directions.
144 observations, 3 features
Singular values: [22.294 11.032 1.827]
Encode and reconstruct
Change k to 1, 2, or 3 and rerun. The rows of Z contain the retained coordinates; X_hat puts those coordinates back into the original feature space. Three coordinates allow exact reconstruction here. With fewer, the residual should be perpendicular to every retained direction.
PCA never increases a distance, but it can shrink different distances by different amounts. Each dot below is one pair of observations. Points on the diagonal retain their distance; points below it lose distance.
We’ll check the full identity, not just the inequality: original squared distance equals embedding squared distance plus discarded squared distance.
Nearest neighbor changed for 30 of 144 observations.
Try keeping one coordinate, then all three. Which statements hold for every pair, and which only describe the total error? Could the reconstruction error be small while the identity of a nearest neighbor changes?
For a new observation, subtract mean, multiply by V_k, and reconstruct with V_k.T. Add mean back only when returning to the original feature units.