Part 8 - Principal Component Analysis

Eigenvectors

Let’s do a quick linear algebra recap.

Assume ARN×N,vCN×1\mathbf{A} \in \mathbb{R}^{N \times N}, \mathbf{v} \in \mathbb{C}^{N \times 1}, and λC\lambda \in \mathbb{C}.

If Av=λv\mathbf{A} \mathbf{v} = \lambda \mathbf{v}, then v\mathbf{v} is a right eigenvector of A\mathbf{A} with eigenvalue λ\lambda.

If ATv=λv\mathbf{A}^T \mathbf{v} = \lambda \mathbf{v}, then v\mathbf{v} is a left eigenvector of A\mathbf{A} with eigenvalue λ\lambda. (Equivalently, vTA=λvT\mathbf{v}^T \mathbf{A} = \lambda \mathbf{v}^T.)

If A\mathbf{A} is symmetric such that A=AT\mathbf{A} = \mathbf{A}^T, then the left and right eigenvectors of A\mathbf{A} are the same with the same eigenvalues.

Example

[2112][11]=[33]=3[11]\begin{bmatrix} 2 & 1 \newline 1 & 2 \end{bmatrix} \begin{bmatrix} 1 \newline 1 \end{bmatrix} = \begin{bmatrix} 3 \newline 3 \end{bmatrix} = 3 \begin{bmatrix} 1 \newline 1 \end{bmatrix} [11][2112]=3[11]\begin{bmatrix} 1 & 1 \end{bmatrix} \begin{bmatrix} 2 & 1 \newline 1 & 2 \end{bmatrix} = 3 \begin{bmatrix} 1 & 1 \end{bmatrix}

Linear Independence

Linear independence is arguably the most important concept in linear algebra.

A set of vectors {v1,v2,,vN}\{\mathbf{v}_1, \mathbf{v}_2, \ldots, \mathbf{v}_N\} is linearly independent if vector equation,

a1v1+a2v2++aNvN=0,a_1 \mathbf{v}_1 + a_2 \mathbf{v}_2 + \ldots + a_N \mathbf{v}_N = \mathbf{0},

has only the trivial solution a1=a2==aN=0a_1 = a_2 = \ldots = a_N = 0.

{v1,v2,,vN}\{\mathbf{v}_1, \mathbf{v}_2, \ldots, \mathbf{v}_N\} is linearly dependent if there exists numbers a1,a2,,aNa_1, a_2, \ldots, a_N not all equal to zero, such that,

a1v1+a2v2++aNvN=0.a_1 \mathbf{v}_1 + a_2 \mathbf{v}_2 + \ldots + a_N \mathbf{v}_N = \mathbf{0}.

Assuming a10a_1 \neq 0, we have v1=a2a1v2aNa1vN\mathbf{v}_1 = -\frac{a_2}{a_1} \mathbf{v}_2 - \ldots - \frac{a_N}{a_1} \mathbf{v}_N.

Some Matrices

An N×NN \times N square matrix A\mathbf{A} is invertible if there exists an N×NN \times N square matrix B\mathbf{B} such that,

AB=BA=IN,\mathbf{A} \mathbf{B} = \mathbf{B} \mathbf{A} = \mathbf{I}_N,

Equivalently, the columns/rows of A\mathbf{A} are linearly independent.

A square matrix Q\mathbf{Q} is orthogonal if its columns and rows are orthogonal unit vectors (orthonormal vectors),

QQT=QTQ=I.\mathbf{Q} \mathbf{Q}^T = \mathbf{Q}^T \mathbf{Q} = \mathbf{I}.

A square matrix A\mathbf{A} is diagonalizable if there exists an invertible matrix P\mathbf{P} and a diagonal matrix D\mathbf{D} such that,

P1AP=D,\mathbf{P}^{-1} \mathbf{A} \mathbf{P} = \mathbf{D},

or equivalently,

A=PDP1.\mathbf{A} = \mathbf{P} \mathbf{D} \mathbf{P}^{-1}.

Real symmetric matrices are diagonalizable by orthogonal matrices. This can be proven by the spectral theorem.

Eigendecomposition

Let VRN×N\mathbf{V} \in \mathbb{R}^{N \times N} be a matrix whose columns vi\mathbf{v_i} are NN linearly independent eigenvectors of A\mathbf{A} with Λ\mathbf{\Lambda} the corresponding diagonal matrix of eigenvalues such taht Λii=λi\Lambda_{ii} = \lambda_i.

Then,

AV=VΛA=VΛV1V1AV=Λ\begin{align*} \mathbf{A} \mathbf{V} & = \mathbf{V} \mathbf{\Lambda} \newline \mathbf{A} & = \mathbf{V} \mathbf{\Lambda} \mathbf{V}^{-1} \newline \mathbf{V}^{-1} \mathbf{A} \mathbf{V} & = \mathbf{\Lambda} \end{align*}

Eigendecomposition of Symmetric Matrix

If A\mathbf{A} is a real symmetric, we can choose NN orthonormal eigenvectors so that vi22=1\Vert \mathbf{v}_i \Vert_2^2 = 1, viTvj=0\mathbf{v}_i^T \mathbf{v}_j = 0 and NN real eigenvalues λiR\lambda_i \in \mathbb{R}.

As a result, we have,

A=VΛVT=i=1NλiviviTVTAV=Λ\begin{align*} \mathbf{A} & = \mathbf{V} \mathbf{\Lambda} \mathbf{V}^T = \sum_{i = 1}^N \lambda_i \mathbf{v_i} \mathbf{v_i}^T \newline \mathbf{V}^T \mathbf{A} \mathbf{V} & = \mathbf{\Lambda} \end{align*}

Principal Component Analysis

Principal Component Analysis (PCA) is an unsupervised method, given a data matrix XRM×N\mathbf{X} \in \mathbb{R}^{M \times N}, the goal of PCA is to identify the directions of maximum variance contained in the data.

We need to choose the basis vectors along the maximum variance (longest extent) of the data. The basis vectors are called principal components (PC).

Sample Variance in a Given Direction

Let vRN\mathbf{v} \in \mathbb{R}^N such that v2=vTv=1\Vert \mathbf{v} \Vert_2 = \mathbf{v}^T \mathbf{v} = 1.

The variance in the direction v\mathbf{v} is given by the expression,

1Mi=1M(vTx(i)μ)2,\frac{1}{M} \sum_{i = 1}^M (\mathbf{v}^T \mathbf{x}^{(i)} - \mathbf{\mu})^2,

where μ=1Mi=1MvTx(i)\mathbf{\mu} = \frac{1}{M} \sum_{i = 1}^M \mathbf{v}^T \mathbf{x}^{(i)} is the mean of the projected data.

Pre-Centering

Under the assumption that the data are pre-centered so that 1Mi=1M(vTx(i))=0\frac{1}{M} \sum_{i = 1}^M (\mathbf{v}^T \mathbf{x}^{(i)}) = 0, this expression simplifies to,

1Mi=1M(vTx(i))2=1Mi=1M(vTx(i))T(vTx(i))=1Mi=1M(vTx(i))T(x(i))T((x(i))Tv)=1MvT(i=1Mx(i)(x(i))T)v=1MvTXTXv.\begin{align*} \frac{1}{M} \sum_{i = 1}^M (\mathbf{v}^T \mathbf{x}^{(i)})^2 & = \frac{1}{M} \sum_{i = 1}^M \left(\mathbf{v}^T \mathbf{x}^{(i)}\right)^T \left(\mathbf{v}^T \mathbf{x}^{(i)}\right) \newline & = \frac{1}{M} \sum_{i = 1}^M \left(\mathbf{v}^T \mathbf{x}^{(i)}\right)^T \left(\mathbf{x}^{(i)}\right)^T \left((\mathbf{x}^{(i)})^T \mathbf{v}\right) \newline & = \frac{1}{M} \mathbf{v}^T \left(\sum_{i = 1}^M \mathbf{x}^{(i)} (\mathbf{x}^{(i)})^T\right) \mathbf{v} \newline & = \frac{1}{M} \mathbf{v}^T \mathbf{X}^T \mathbf{X} \mathbf{v}. \end{align*}

The Direction of Maximum Variance

Suppose we want to identify the direction v1\mathbf{v}_1 of maximum variance given the data matrix X\mathbf{X}.

We can formulate this optimization problem as follows,

maxv1MvTXTXvsubject tov2=1.\begin{align*} \underset{\mathbf{v}}{\max} & \quad \frac{1}{M} \mathbf{v}^T \mathbf{X}^T \mathbf{X} \mathbf{v} \newline \text{subject to} & \quad \Vert \mathbf{v} \Vert_2 = 1. \end{align*}

Letting Σ=1MXTX\mathbf{\Sigma} = \frac{1}{M} \mathbf{X}^T \mathbf{X}, we form the Lagrangian,

L(v,ν)=vTΣv+ν(1v22).L(\mathbf{v}, \nu) = \mathbf{v}^T \mathbf{\Sigma} \mathbf{v} + \nu (1 - \Vert \mathbf{v} \Vert_2^2).

Taking the derivative of L(v,ν)L(\mathbf{v}, \nu) with respect to v\mathbf{v} and setting it to zero, we have,

L(v,ν)v=2Σv2νv=0Σv=νv.\begin{align*} \frac{\partial L(\mathbf{v}, \nu)}{\partial \mathbf{v}} & = 2 \mathbf{\Sigma} \mathbf{v} - 2 \nu \mathbf{v} = 0 \newline \mathbf{\Sigma} \mathbf{v} & = \nu \mathbf{v}. \end{align*}

As v0,v\mathbf{v} \neq 0, \mathbf{v} must be an eigenvector of Σ\mathbf{\Sigma} with eigenvalue ν\nu.

Assuming {v1,v2,,vN}\{\mathbf{v}_1, \mathbf{v}_2, \ldots, \mathbf{v}_N\} are the eigenvectors of Σ\mathbf{\Sigma}, corresponding to eigenvalues σ1σN\sigma_1 \geq \ldots \geq \sigma_N, respectively, we have,

v=v1p=v1TΣv1=v1Tνv1=νv1Tv1=ν=σ1.\begin{align*} \mathbf{v}^{\star} & = \mathbf{v}_1 \newline p^{\star} & = \mathbf{v}_1^T \mathbf{\Sigma} \mathbf{v}_1 = \mathbf{v}_1^T \nu \mathbf{v}_1 = \nu \mathbf{v}_1^T \mathbf{v}_1 = \nu = \sigma_1. \end{align*}

KK Largest Directions of Variance

Suppose instead of just the direction of maximum variance, we want the KK largest directions of variance that are all mutually orthogonal.

Finding the second-largest direction of variance corresponds to solving the problem,

maxv1MvTXTXvsubject tov2=1,vTv1=0.\begin{align*} \underset{\mathbf{v}}{\max} & \quad \frac{1}{M} \mathbf{v}^T \mathbf{X}^T \mathbf{X} \mathbf{v} \newline \text{subject to} & \quad \Vert \mathbf{v} \Vert_2 = 1, \newline & \quad \mathbf{v}^T \mathbf{v}_1 = 0. \end{align*}

We form the Lagrangian,

L(v,ν,λ)=vTΣv+ν(1v22)+λvTv1.L(\mathbf{v}, \nu, \lambda) = \mathbf{v}^T \mathbf{\Sigma} \mathbf{v} + \nu (1 - \Vert \mathbf{v} \Vert_2^2) + \lambda \mathbf{v}^T \mathbf{v}_1.

Taking the derivative of L(v,ν,λ)L(\mathbf{v}, \nu, \lambda) with respect to v\mathbf{v} and setting it to zero, we have,

L(v,ν,λ)v=2Σv2νv+λv1=0.\frac{\partial L(\mathbf{v}, \nu, \lambda)}{\partial \mathbf{v}} = 2 \mathbf{\Sigma} \mathbf{v} - 2 \nu \mathbf{v} + \lambda \mathbf{v}_1 = 0.

If we left-multiply by v1T\mathbf{v}_1^T on both sides, we have,

2v1TΣv2νv1Tv+λv1Tv1=02(Σv1)Tv0+λ=02σ1v1Tv0+λ=0λ=0.\begin{align*} 2 \mathbf{v_1}^T \mathbf{\Sigma} \mathbf{v} - 2 \nu \mathbf{v_1}^T \mathbf{v} + \lambda \mathbf{v_1}^T \mathbf{v_1} & = 0 \newline 2(\mathbf{\Sigma} \mathbf{v_1})^T \mathbf{v} - 0 + \lambda & = 0 \newline 2 \sigma_1 \mathbf{v_1}^T \mathbf{v} - 0 + \lambda & = 0 \newline \lambda = 0. \end{align*}

Therefore, we arrive at the eigenvalue equation again,

Σv=νv.\mathbf{\Sigma} \mathbf{v} = \nu \mathbf{v}.

It is easy to see that v\mathbf{v}^{\star} is the eigenvector corresponding to the second largest eigenvalue.

In general, the top KK directions of variance v1,,vK\mathbf{v}_1, \ldots, \mathbf{v}_K are given by the KK eigenvectors corresponding to the KK largest eigenvalues of 1MXTX\frac{1}{M} \mathbf{X}^T \mathbf{X}.

PCA can also be derived by picking the principal vectors that minimize the approximation error arising from projecting the data onto the KK-dimensional subspace spanned by these vectors,

minV1Mi=1Mx(i)(vTx(i))v22.\underset{\mathbf{V}}{\min} \frac{1}{M} \sum_{i = 1}^M \Vert \mathbf{x}^{(i)} - (\mathbf{v}^T \mathbf{x}^{(i)}) \mathbf{v} \Vert_2^2.

Dimensionality Reduction with PCA

The informal algorithm can be described as follows,

  1. Subtract the mean of the data.
  2. The first PC v1\mathbf{v}_1 is the direction that explains the most variance of the data.
  3. The second PC v2\mathbf{v}_2 is the direction perpendicular to v1\mathbf{v}_1 that explains the most variance.
  4. The third PC v3\mathbf{v}_3 is the direction perpendicular to {v1,v2}\{\mathbf{v}_1, \mathbf{v}_2\} that explains the most variance.
  5. \ldots

The formal algorithm can be described as follows,

  1. Data preprocessing: Compute μ=1Mix(i)\mathbf{\mu} = \frac{1}{M} \sum_i \mathbf{x}^{(i)} and replace each x(i)\mathbf{x}^{(i)} with x(i)μ\mathbf{x}^{(i)} - \mathbf{\mu}.
  2. Given pre-processed data matrix XRM×N\mathbf{X} \in \mathbb{R}^{M \times N}, compute the sample covariance matrix Σ=1MXTX\mathbf{\Sigma} = \frac{1}{M} \mathbf{X}^T \mathbf{X}.
  3. Compute the KK leading eigenvectors v1,,vK\mathbf{v}_1, \ldots, \mathbf{v}_K of Σ\mathbf{\Sigma} where viRN\mathbf{v}_i \in \mathbb{R}^N.
  4. Stack the eigenvectors together into an N×KN \times K matrix V\mathbf{V} where each column ii of V\mathbf{V} corresponds to vi\mathbf{v}_i.
  5. Project the matrix X\mathbf{X} into the rank-KK subspace of maximum variance by computing the matrix product Z=XV\mathbf{Z} = \mathbf{X} \mathbf{V}.
  6. To reconstruct X\mathbf{X} given Z\mathbf{Z} and V\mathbf{V}, we use X^=ZVT\mathbf{\hat{X}} = \mathbf{Z} \mathbf{V}^T.

How to Choose the Number of PCs?

We have two methods to set the number of components KK.

  • Preserve some percentage of the variance, e.g., 95%.
  • Whatever works well for our final task (e.g., classification, regression).

Connection to SVD

We have seen that the minimum Frobenius norm linear dimensionality reduction problem could be solved using the rank-KK SVD of X\mathbf{X},

argminU,S,VXUSVTF2,\begin{align*} \underset{\mathbf{U}, \mathbf{S}, \mathbf{V}}{\arg \min} & \quad \Vert \mathbf{X} - \mathbf{U} \mathbf{S} \mathbf{V}^T \Vert_F^2, \end{align*}

where URM×K\mathbf{U} \in \mathbb{R}^{M \times K}, SRK×K\mathbf{S} \in \mathbb{R}^{K \times K}, and VRN×K\mathbf{V} \in \mathbb{R}^{N \times K}.

The matrix Z=US\mathbf{Z} = \mathbf{U} \mathbf{S} gives the optimal rank-KK representation of X\mathbf{X} with respect to Frobenius norm minimization.

If we let K=NK = N then X=USVT\mathbf{X} = \mathbf{U} \mathbf{S} \mathbf{V}^T and XTX=VSTUTUSVT\mathbf{X}^T \mathbf{X} = \mathbf{V} \mathbf{S}^T \mathbf{U}^T \mathbf{U} \mathbf{S} \mathbf{V}^T.

Due to orthogonality of U\mathbf{U}, we get XTX=VS2VT\mathbf{X}^T \mathbf{X} = \mathbf{V} \mathbf{S}^2 \mathbf{V}^T.

This means that the right singular vectors of X\mathbf{X} are exactly the eigenvectors of XTX\mathbf{X}^T \mathbf{X}.

We can also see that the eigenvalues of XTX\mathbf{X}^T \mathbf{X} are the squares of the diagonal elements of S\mathbf{S}.

This means that the KK largest singular values and KK largest eigenvalues correspond to the same KK basis vectors.

According to PCA, the projection operation is Z=XV\mathbf{Z} = \mathbf{X} \mathbf{V}, therefore,

Z=XV=(USVT)(V)=US.\mathbf{Z} = \mathbf{X} \mathbf{V} = (\mathbf{U} \mathbf{S} \mathbf{V}^T)(\mathbf{V}) = \mathbf{U} \mathbf{S}.

Finally, note that if the decomposition are based only on the KK leading principal vectors, the projections Z=XV\mathbf{Z} = \mathbf{X} \mathbf{V} and Z=US\mathbf{Z} = \mathbf{U} \mathbf{S} will still be identical.

These manipulations show that PCA on XTX\mathbf{X}^T \mathbf{X} and SVD on X\mathbf{X} identify exactly the same subspace and result in exactly the same projection of the data into that subspace.

As a result, generic linear dimensionality reduction simultaneously minimizes the Frobenius norm of the reconstruction error of X\mathbf{X} and maximizes the retained variance in the learned subspace.

Both SVD and PCA provide the same description of generic linear dimensionality reduction, an orthogonal basis for exactly the same optimal linear subspace.

When Does PCA Fail?

The primary motivation behind PCA is to decorrelate the dataset, i.e., remove second-order dependencies.

If higher-order dependencies exist between the features in the data, PCA may be insufficient at revealing all strucutre in the data.

PCA requires that each component must be perpendicular to the previous ones, but clearly, this requirement is overly stringent and the data might be arranged along non-orthogonal axes.

Kernel Principal Component Analysis

Kernel PCA (KPCA) is a non-linear extension of PCA that can be used to extract non-linear structure in the data.

Limitations of Linear Dimensionality Reduction

What if the data “lives” on a non-flat surface?

PCA can not capture the curvature of the data.

As usual, feature mapping can be used to overcome this.

Feature Mapping

If we apply a high-dimensional feature transformation to the data x(i)ϕ(x(i))\mathbf{x}^{(i)} \rightarrow \phi(\mathbf{x}^{(i)}), we can project the high-dimensional data to a linear surface, i.e., run PCA on ϕ(X)\phi(\mathbf{X}). In the original space, the projection will be non-linear.

Feature Mapping + SVD

Given a data set XRM×N\mathbf{X} \in \mathbb{R}^{M \times N} and a feature mapping function ϕ:RNRL\phi : \mathbb{R}^N \mapsto \mathbb{R}^L for L>NL > N, we obtain the following SVD-based algorithm,

  1. Compute U,S,V=SVD(ϕ(X))\mathbf{U}, \mathbf{S}, \mathbf{V} = \text{SVD}(\phi(\mathbf{X})).
  2. Return Z=US\mathbf{Z} = \mathbf{U} \mathbf{S}.

Feature Mapping + PCA

Given a data set XRM×N\mathbf{X} \in \mathbb{R}^{M \times N} and a feature mapping function ϕ:RNRL\phi : \mathbb{R}^N \mapsto \mathbb{R}^L for L>NL > N, we obtain the following PCA-based algorithm,

  1. Compute Σ=1Mi(ϕ(x(i)μ))(ϕ(x(i)μ))T\mathbf{\Sigma} = \frac{1}{M} \sum_i (\phi(\mathbf{x}^{(i)} - \mathbf{\mu})) (\phi(\mathbf{x}^{(i)} - \mathbf{\mu}))^T. where μ=1Miϕ(x(i))\mathbf{\mu} = \frac{1}{M} \sum_i \phi(\mathbf{x}^{(i)}).

  2. Compute the KK leading eigenvectors v1,,vK\mathbf{v}_1, \ldots, \mathbf{v}_K of Σ\mathbf{\Sigma} where vjRL\mathbf{v}_j \in \mathbb{R}^L for j=1,,Kj = 1, \ldots, K.

  3. Stack the eigenvectors together to form V=[v1,v2,,vK]\mathbf{V} = [\mathbf{v}_1, \mathbf{v}_2, \ldots, \mathbf{v}_K], where VRL×K\mathbf{V} \in \mathbb{R}^{L \times K}.

  4. Project the matrix ϕ(X)\phi(\mathbf{X}) into the rank-KK subspace of maximum variance by computing the matrix product Z=ϕ(X)V\mathbf{Z} = \phi(\mathbf{X}) \mathbf{V}.

Kernel PCA

As in classification, it becomes very expensive to use an explicit feature function to map data into a high-dimensional space.

In the basic SVD-based algortihm, there’s no way to avoid this problem.

However, in the PCA-based algorithm, we are able to take advantage of the kernel trick,

K(x(i),x(j))=ϕ(x(i))Tϕ(x(j)).\mathcal{K}(\mathbf{x}^{(i)}, \mathbf{x}^{(j)}) = \phi(\mathbf{x}^{(i)})^T \phi(\mathbf{x}^{(j)}).

Given ϕ:RNRL\phi : \mathbb{R}^N \mapsto \mathbb{R}^L, we can compute the covariance matrix in the new feature space,

Σ=1Mj=1Mϕ(x(i))ϕ(x(j))T.\mathbf{\Sigma} = \frac{1}{M} \sum_{j = 1}^M \phi(\mathbf{x}^{(i)}) \phi(\mathbf{x}^{(j)})^T.

Note that we have assumed that the data is pre-centered in our new feature space. If this turns out to be false, we can center the data by subtracting the mean of the data in the new feature space.

Eigendecomposition of Σ\mathbf{\Sigma} is given by,

Σvk=1Mj=1Mϕ(x(i))ϕ(x(j))Tvk=λkvk,k=1,,L.\mathbf{\Sigma} \mathbf{v_k} = \frac{1}{M} \sum_{j = 1}^M \phi(\mathbf{x}^{(i)}) \phi(\mathbf{x}^{(j)})^T \mathbf{v}_k = \lambda_k \mathbf{v}_k, \forall k = 1, \ldots, L.

It is not hard to see that vk\mathbf{v}_k can be expressed as,

vk=j=1Mwk(j)ϕ(x(j)),\mathbf{v_k} = \sum_{j = 1}^M w_k^{(j)} \phi(\mathbf{x}^{(j)}),

where wk(j)=1Mλkϕ(x(j))Tvkw_k^{(j)} = \frac{1}{M \lambda_k} \phi(\mathbf{x}^{(j)})^T \mathbf{v}_k.

So, the kernel PCA is a linear combination of high-dimensional vectors, and wk(j)w_k^{(j)} are weights to be determined.

If we left-multiply ϕ(x(i))T\phi(\mathbf{x}^{(i)})^T to both sides, we have,

ϕ(x(i))Tvk=j=1Mwk(j)ϕ(x(i))Tϕ(x(j))=Mλkwk(i).\phi(\mathbf{x}^{(i)})^T \mathbf{v_k} = \sum_{j = 1}^M w_k^{(j)} \phi(\mathbf{x}^{(i)})^T \phi(\mathbf{x}^{(j)}) = M \lambda_k w_k^{(i)}.

Defining the kernel matrix KRM×M\mathbf{K} \in \mathbb{R}^{M \times M}, where Kij=K(x(i),x(j))=ϕ(x(i))Tϕ(x(j))K_{ij} = \mathcal{K}(\mathbf{x}^{(i)}, \mathbf{x}^{(j)}) = \phi(\mathbf{x}^{(i)})^T \phi(\mathbf{x}^{(j)}).

Then,

j=1MKijwk(j)=Mλkwk(i).\sum_{j = 1}^M K_{ij} w_k^{(j)} = M \lambda_k w_k^{(i)}.

If we consider i=1,,Mi = 1, \ldots, M, the above scalar equation becomes the ii-th component of the following vector equation,

Kwk=Mλkwk,\mathbf{K} \mathbf{w}_k = M \lambda_k \mathbf{w}_k,

where wk=[wk(1),wk(2),,wk(M)]T\mathbf{w}_k = [w_k^{(1)}, w_k^{(2)}, \ldots, w_k^{(M)}]^T is the kk-th eigenvector of K\mathbf{K}.

MλkM \lambda_k is the eigenvalue of K\mathbf{K}, which is proportional to the eigenvalue λk\lambda_k of the covariance matrix Σ\mathbf{\Sigma} in the feature space.

Therefore, PCA on Σ\mathbf{\Sigma} is equivalent to PCA on K\mathbf{K}.

For a new point x\mathbf{x}^{\star}, the kk-th kernel PC can be obtained by projection ϕ(x)\phi(\mathbf{x}^{\star}) on the kk-th eigenvector vk\mathbf{v}_k of Σ\mathbf{\Sigma}.

ϕ(x)Tvk=i=1wk(i)ϕ(x)Tϕ(x(i))=i=1wk(i)K(x,x(i)).\phi(\mathbf{x}^{\star})^T \mathbf{v_k} = \sum_{i = 1} w_k^{(i)} \phi(\mathbf{x}^{\star})^T \phi(\mathbf{x}^{(i)}) = \sum_{i = 1} w_k^{(i)} \mathcal{K}(\mathbf{x}^{\star}, \mathbf{x}^{(i)}).

Kernel PCA Algorithm

Given a data set XRM×N\mathbf{X} \in \mathbb{R}^{M \times N} and a kernel function K\mathcal{K}, kernel PCA can be computed as follows,

  1. Compute Kij=K(x(i),x(j))K_{ij} = \mathcal{K}(\mathbf{x}^{(i)}, \mathbf{x}^{(j)}) for all i,ji,j.

  2. Compute K=(I1M)K(I1M)\mathbf{K}^{\prime} = (\mathbf{I} - \mathbf{1}_M) \mathbf{K} (\mathbf{I} - \mathbf{1}_M) where 1M\mathbf{1}_M is an M×MM \times M matrix where every entry is 1M\frac{1}{M}. The goal is to zero center data points in the feature space.

  3. Compute the KK leading eigenvectors w1,,wK\mathbf{w}_1, \ldots, \mathbf{w}_K of K\mathbf{K}^{\prime} along with their eigenvalues Mλ1,,MλKM \lambda_1, \ldots, M \lambda_K.

  4. Compute the kk-th PC of the projected data vector zRK×1\mathbf{z} \in \mathbb{R}^{K \times 1},

zk=i=1Mwk(i)K(x,x(i)).z_k = \sum_{i = 1}^M w_k^{(i)} \mathcal{K}(\mathbf{x}, \mathbf{x}^{(i)}).

Summary

Kernel PCA uses the kernel trick to peform PCA in high-dimensional space.

  • Coeffcients are based on a non-linear projection of the data.
  • The type of projection is based on the kernel function selected.

Using RBF kernel, KPCA can split the data into clusters.

Kernel PCA can provide an effective pre-processing step for clustering methods as well as linear classification and regression methods.

However, exact compuation of kernel PCA can be expensive because the size of the matrix to be decomposed is M×MM \times M.