We now have every ingredient. PCA can be computed from an matrix of dot products, and a kernel supplies dot products in a feature space we never have to construct. Putting the two together gives kernel PCA: non-linear dimensionality reduction at the cost of an eigen-decomposition.
The algorithm, first draft
Input: data and a valid kernel .
- Build the kernel matrix with .
- Eigen-decompose it: unit eigenvectors with eigenvalues
- Rescale: .
In ordinary PCA the next step was . Here the same step would read
and that needs , which we are not allowed to compute (for the RBF kernel it is infinite-dimensional). So we cannot write down the principal directions in the feature space.
We never needed the directions
What do we actually use PCA for? Usually not for the directions themselves, but for each point's coordinates along them: the compressed representation. The coordinate of point on the -th direction is
Only kernel values appear. So each point's new representation is
Read it this way: row of lists how similar is to every training point, and each component weights those similarities in its own way. A new point is handled the same way, using the similarities to the training points.
What we give up is reconstruction. Turning coefficients back into a point needs the directions , which live in the feature space. For most uses (visualisation, clustering, or feeding a classifier) the coordinates are what matter, and we have them.
Note that can exceed the original . With two-dimensional data and an RBF kernel you might keep ten components. That is not a contradiction: the data has been lifted to a much larger space where its curved structure is flat, and ten coordinates in that space can describe it far better than the original two.
The missing step: centring in feature space
Ordinary PCA centred the data first. Kernel PCA needs the mapped points centred, but we cannot subtract their mean because we cannot compute any of them. Fortunately the dot products of the centred points can be written using only kernel values:
Each term comes from expanding the product: the original kernel value, minus the average similarity of to all points, minus that of , plus the overall average. In matrix form, with the matrix whose every entry is ,
Use in place of from step 2 onwards.
Kernel PCA, complete
- Compute .
- Centre it: .
- Eigen-decompose : unit eigenvectors , eigenvalues , largest first.
- Rescale: .
- Represent each training point by its coordinates , for .
Choosing the kernel
The kernel decides what structure kernel PCA can find. A polynomial kernel of degree 2 can flatten circles, ellipses and parabolas; higher degrees capture more intricate surfaces. The RBF kernel can follow almost any smooth shape, with controlling how local it is: a small makes every point similar only to its immediate neighbours (very flexible, prone to fitting noise), a large makes the kernel behave almost linearly. With a linear kernel, , kernel PCA is exactly ordinary PCA.
The bigger lesson
Look at how kernel PCA came about. We solved the problem for linear structure, noticed the solution needed only dot products between data points, and swapped those dot products for a kernel. That recipe, solve it linearly, check that only dot products appear, then kernelise, is general. We will apply it again to regression in Module 6 and to support vector machines in Module 10.