Given data matrix X∈Rn×d (n samples, d features), first center it:
Xc=X−1nμT
where μ=n1∑i=1nxi is the mean vector.
Why center? PCA finds directions through the data's "center of mass". Without centering, the first PC might just point toward the mean instead of capturing variance structure. Centering makes the coordinate origin the data's centroid.
Why the constraint? Without it, we could make variance arbitrarily large by scaling w1. The unit constraint means we're finding a direction, not a magnitude.
Lagrangian:
L=w1TCw1−λ(w1Tw1−1)
Taking derivative with respect to w1 and setting to zero:
∂w1∂L=2Cw1−2λw1=0
Why derivative? We're finding critical points. The factor of 2 appears from differentiating quadratic forms: ∂w∂(wTAw)=2Aw when A is symmetric.
This gives:
Cw1=λw1
This is the eigen-equation! w1 must be an eigenvector of C with eigenvalue λ.
Which eigenvector? Substituting back into our objective:
w1TCw1=w1T(λw1)=λw1Tw1=λ
The variance captured equals λ! To maximize variance, choose the eigenvector with the largest eigenvalue.
For the second PC w2, we maximize variance subject to:
∥w2∥=1 (unit length)
w2Tw1=0 (orthogonal to first PC)
Mathematical reason: Eigenvectors of a symmetric matrix (like covariance matrices) corresponding to distinct eigenvalues are automatically orthogonal. Since covariance matrices are symmetric real matrices, they have a complete set of orthonormal eigenvectors.
Intuitive reason: If w2 had any component along w1, that component would capture variance already captured by w1 (redundant). Orthogonality ensures each PC captures new, uncorrelated variance.
Why this formula? The Frobenius norm squared equals the sum of eigenvalues we didn't include. Each discarded PC contributes its eigenvalue to the error.
After projection, covariance of Z is diagonal:
Cov(Z)=n1ZTZ=Λk=diag(λ1,…,λk)
Meaning: Principal components are uncorrelated. We've decorelated the data.
Recall Explain to a 12-Year-Old
Imagine your class takes a photo together. You have everyone's position in3D space (left-right, forward-back, up-down). But when you look at the photo, you realize most of the information is in just 2 dimensions—the photo plane! The 3rd dimension (depth) barely matters because everyone was standing at roughly the same distance from the camera.
PCA is like finding the "photo angle" for data. It looks at your data cloud and asks: "If I had to take a picture (project onto fewer dimensions), which angle keeps the most information?" The first principal component is like the camera's main direction—it captures where people are most spread out. The second PC is like looking from the side to catch any remaining spread.
Why do we want fewer dimensions? Imagine describing everyone's position. Instead of saying "3.2m left, 1.8m forward, 0.1m higher than Sarah," you could just say "Row 3, Position 7" if everyone's standing in neat rows. Two numbers instead of three! PCA finds those "neat rows" in mesy data.
Variance — The quantity PCA maximizes in successive orthogonal directions
#flashcards/ai-ml
What is the goal of PCA? :: Find orthogonal directions that maximize variance in the data, enabling dimensionality reduction while preserving the most information.
Why must we center data before PCA?
So the first PC captures variance structure rather than just pointing toward the mean; PCA seeks variance around the centroid, not from the origin.
What is a principal component mathematically?
An eigenvector of the covariance matrix; the k-th PC is the eigenvector corresponding to the k-th largest eigenvalue.
What does the eigenvalue represent in PCA?
The variance captured by the corresponding principal component; larger eigenvalue = more variance explained.
How do we compute the covariance matrix for PCA?
C=n1XcTXc where Xc is the centered data matrix (rows are samples, columns are features).
Why are principal components orthogonal?
(1) Eigenvectors of symmetric matrices with distinct eigenvalues are orthogonal. (2) Ensures each PC captures independent variance, no redundancy.
How do we project data onto the first k principal components?
Z=XcWk where Wk contains the first k eigenvectors as columns.
What is the reconstruction formula in PCA?
X^c=ZWkT=XcWkWkT, then add back mean: X^=X^c+1nμT.
What is the reconstruction error when keeping k components?
MSE=∑i=k+1dλi — the sum of discarded eigenvalues equals the squared error.
How much variance do k components explain?
∑i=1dλi∑i=1kλi — ratio of sum of kept eigenvalues to total sum.
Is PCA feature selection or feature extraction?
Feature extraction; it creates new features (linear combinations of all originals), not selecting a subset.
Why standardize features before PCA?
Because PCA is not scale-invariant; features with larger numeric scales dominate variance. Standardizing puts all features on equal footing.
What is the difference between covariance-based and correlation-based PCA?
Covariance PCA uses raw data; correlation PCA uses standardized data (equivalent to computing eigenvectors of correlation matrix). Use correlation when features have different units.
How does SVD relate to PCA?
Xc=UΣVT; principal components are right singular vectors V, eigenvalues are λi=σi2/n. More numerically stable.
What is the covariance structure in PC space?
Diagonal — Cov(Z)=Λk. Principal components are uncorrelated by construction.
PCA ka matlab hai Principal Component Analysis – yek technique hai jisse hum high-dimensional data ko kam dimensions mein convert kar sakte hain, lekin important information retain rahti hai. Socho ki tumhare pas 100 features hain (100 columns), lekin asli mein sirf 3-4 "directions" mein sab variation hai. PCA un important directions ko dhondh leta hai.
Mathematically, PCA covariance matrix ke eigenvectors nikalta hai. Covariance