Skip to main content

PCA

PCA means principal component analysis. It is a technique used to reduce the dimensionality of the dataset.

The idea is very simple, consider a dataset matrix,

X=(x1,x2,,xn)TX = (x_1, x_2, \ldots, x_n)^T

We would like to retain the dimension that captures the most variance in the dataset.

Consider the covariance matrix, C=(XX)T(XX)C = (X - \overline{X})^T(X - \overline{X}) where X=(x,x,,x)T\overline{X} = (\overline{x}, \overline{x}, \ldots, \overline{x})^T. Because we want maximum variance for each dimension, we can perform an eigendecomposition of the covariance matrix.

C=VTΛVC = V^T \Lambda V

Now, if vv is an eigenvector, if the original data has greater variance along vv, it will have a greater eigenvalue. We can choose ones that have the largest eigenvalues, then,

V=(v1,v2,,vk)TV = (v_1, v_2, \ldots, v_k)^T

Then we project XX to this reduced eigenspace,

X=XVX' = X V

Thus accomplishing the task of choosing the important basis (the principal components) of the dataset.

info

The above process can also be seen as SVD on the dataset matrix XXX - \overline{X}.

From the SVD perspective, the principal components are the left singular vectors of XXX - \overline{X}. The eigenvalues of the covariance matrix are the square of the singular values of XXX - \overline{X}. We look for the singular vectors that has the largest absolute singular values, then cast the data into the reduced singular vector space.

tip

Singular Value Decomposition refers to decomposing a matrix into,

X=UΣVTX = U \Sigma V^T

Where UU and VV are orthogonal matrices and Σ\Sigma is a diagonal (maybe not square) matrix. This is a natural extension of the eigendecomposition of a square matrix.

UU and VV are the left and right singular vectors of XX respectively. Σ\Sigma is the singular values of XX. For a square matrix, the singular values are the eigenvalues.

UU is responsible for rotating the vector into a proper basis, then Σ\Sigma brings the space into a another dimension while performing a stretch, then VV rotates the target space.

To calculate the SVD,

XTX=VΣ2VTX^T X = V \Sigma^2 V^T

Because XTXX^T X is a square matrix, it has an eigendecomposition. The eigenvectors of XTXX^T X are the right singular vectors of XX. The eigenvalues of XTXX^T X are the square of the singular values of XX.

Similarly,

XXT=UΣ2UTX X^T = U \Sigma^2 U^T

Thus we can calculate the singular values and vectors of XX.