Kernel PCA

Machine Learning
Introduced by
Schölkopf, B.; Smola, A. J.; Müller, K.-R.
Year
1998
Type
Nonlinear dimensionality reduction via kernel trick

What does it do?

Kernel Principal Component Analysis (Kernel PCA) is a nonlinear dimensionality-reduction method introduced by Bernhard Schölkopf, Alexander Smola and Klaus-Robert Müller, presented at ICANN'97 and in a 1998 paper in Neural Computation.

It extends linear PCA by computing principal components in a feature space induced by a kernel function, so the data are never mapped into that space explicitly. The result is a set of nonlinear components that can describe structure which straight-line directions in the input space do not capture.

The intuition behind the method

Standard PCA finds the directions of greatest variance in the original input space, and those directions are straight lines. Many datasets lie on curved or twisted structures, which straight directions summarise poorly. Kernel PCA conceptually maps the data into a higher-dimensional feature space where such structure may become linear, and then performs PCA there. The kernel trick makes this practical: the required quantities are inner products in feature space, and they can be obtained by evaluating a kernel function on pairs of original inputs. The resulting components can separate arrangements such as concentric rings, which linear PCA cannot separate.

History

The kernel trick, which replaces inner products with kernel evaluations so that computation takes place implicitly in a feature space, was already in use in support vector machines. Schölkopf, Smola and Müller applied it to PCA, first at ICANN'97 under the title 'Kernel principal component analysis' and then in the 1998 Neural Computation paper 'Nonlinear component analysis as a kernel eigenvalue problem'. The 1998 paper derives the method and reports experiments on polynomial feature extraction for pattern recognition. Approximate versions based on the Nyström method and on random Fourier features were developed later to handle larger datasets.

When to use it

Choose Kernel PCA when unlabelled data have nonlinear variance structure and a kernel can encode a meaningful notion of similarity, for example when groups form rings or curved manifolds that linear PCA cannot separate. It is a reasonable feature-extraction step before a linear classifier when the raw inputs are not linearly separable. It is less suitable when the sample size is large, because the n × n kernel matrix must be stored and decomposed, unless approximations such as the Nyström method are used. Do not choose it when you need a decoder that reconstructs inputs, since no closed-form pre-image exists, or when you need class-discriminative directions, for which supervised kernel methods are designed. The kernel and its hyperparameters, such as the RBF bandwidth, must be selected, and the number of retained components usually requires inspecting the eigenvalue spectrum.

Limitations and considerations

  • The eigendecomposition of the n × n kernel matrix costs O(n^3), and storing the matrix costs O(n^2), so exact Kernel PCA becomes impractical for large sample sizes without approximation.
  • There is no closed-form pre-image map back to input space; reconstruction requires an iterative pre-image approximation, which can be unstable.
  • The kernel type and its hyperparameters, such as the RBF bandwidth, are not chosen automatically, and the embedding can change substantially with them; validation is needed.
  • The method is unsupervised and does not optimise class separation, so discriminative tasks need a downstream classifier or a supervised kernel method.
  • Components are expansions in feature space rather than weighted combinations of the original variables, so they cannot be reported as loadings in input units as classical PCA allows.

Source conditions do not replace independent scientific review or validation by an analysis engine.

Strengths

  • Captures nonlinear variance structure through the kernel, so it can describe arrangements such as concentric rings that linear PCA cannot separate.
  • Uses only kernel evaluations: the feature map is never computed explicitly, so the implicit feature space can be very high-dimensional.
  • Reduces to an eigendecomposition, a standard linear-algebra problem with a single global solution, rather than an iterative non-convex optimisation.
  • New points are projected with the same kernel evaluations against the training points, so the embedding extends out of sample without refitting.
  • The kernel is a design choice: RBF, polynomial and sigmoid kernels are all admissible, so the notion of similarity can be adapted to the data.

Applications

  • Nonlinear feature extraction before a linear classifier when the raw inputs are not linearly separable, the use explored in the 1998 pattern-recognition experiments.
  • Visualisation of data with nonlinear structure, where a fixed mapping that extends to new points is preferred over a neighbourhood-based embedding.
  • Novelty detection, where new points with unusual projections relative to the training components may be flagged.
  • Preprocessing for spectral clustering, where a kernel matrix is decomposed and its eigenvectors are used as input features.

How it works

How it works

1

For every pair of training points, a kernel function k(x_i, x_j) is evaluated to fill the n × n Gram matrix K, whose entries are pairwise similarities in the implicit feature space. Common choices include the Gaussian (RBF), polynomial and sigmoid kernels. The choice of kernel and its hyperparameters is the main modelling decision, and it should reflect the geometry of the data. Because the Gram matrix is built only from kernel values, the feature map itself is never computed.

Formula
K_{ij} = k(\mathbf{x}_i, \mathbf{x}_j)
2

Principal components are defined with respect to centred data, so the Gram matrix is centred algebraically. Here 1_n denotes the n × n matrix whose entries all equal 1/n, so that the formula above is the double centring K̃ = (I − 1_n) K (I − 1_n). This removes the feature-space mean without forming the features. Omitting this step means the eigenvectors no longer correspond to principal components of the feature-space covariance. The centred matrix K̃ carries the feature-space variance structure after mean removal.

Formula
\tilde{K} = K - \mathbf{1}_n K - K \mathbf{1}_n + \mathbf{1}_n K \mathbf{1}_n
3

The feature-space principal components are obtained from the eigenvalue equation n·λ·α = K̃·α, where each α is a coefficient vector of length n and λ is the associated eigenvalue. Unlike ordinary PCA, which decomposes a p × p covariance matrix, this step decomposes the n × n centred kernel matrix, so its cost depends on the number of samples rather than on the input dimension. Eigenvalues are examined to decide how many components to retain. A common rule is to compute the cumulative fraction of the sum of the retained eigenvalues over the sum of all positive eigenvalues and keep the smallest number of components that reaches a chosen level, then confirm the choice by downstream performance. The spectrum often shows no clear gap, so the choice is a judgement rather than a test.

Formula
n \lambda \alpha = \tilde{K} \alpha
4

A training or new point x is projected onto the r-th component as a weighted sum of kernel evaluations against the training points, with the coefficients α^r as weights. This gives the scalar y_r(x), and taking the first d components yields the nonlinear embedding of x. The scale of y_r depends on how α^r is normalised. A standard convention is to scale the coefficients so that the feature-space eigenvectors have unit norm; in the Gram-matrix formulation this corresponds to α^r = u^r / d_r, where u^r is the unit-length r-th eigenvector of the centred kernel matrix and d_r the square root of its eigenvalue. For a new point, the kernel values k(x_i, x) must be centred consistently with the training data before the weighted sum is taken. Check the normalisation convention before comparing values across implementations.

Formula
y_r(\mathbf{x}) = \sum_{i=1}^{n} \alpha_i^r \, k(\mathbf{x}_i, \mathbf{x})

Common pitfalls

  • Omitting the centring of the Gram matrix, which breaks the interpretation of the eigenvectors as principal components.
  • Ignoring the normalisation of the coefficients α^r, which rescales the projections y_r and makes component values incomparable across implementations.
  • Using an RBF bandwidth on unstandardised inputs: the kernel depends on distances between points, so variables measured in large units can dominate the similarity.
  • Applying the method to large sample sizes without a landmark or low-rank approximation, which can lead to memory failures or long runtimes.
  • Projecting new points using raw kernel values: the vector of kernel values between a new point and the training points must be centred consistently with the training Gram matrix, otherwise the projections are shifted.
  • Confusing Kernel PCA with kernel Fisher discriminant analysis: Kernel PCA is unsupervised and does not use class labels to optimise separation.

Frequently asked questions

Which kernel should I choose?

There is no universally best kernel. The Gaussian (RBF) kernel with bandwidth σ is a common default and is appropriate when local distances are a sensible measure of similarity. Polynomial kernels suit data where polynomial interactions between variables are expected. In practice, compare two or three kernels with cross-validated bandwidth or degree selection, and judge the resulting embeddings both visually and by downstream task performance.

How is Kernel PCA different from t-SNE or UMAP?

Kernel PCA computes a linear projection in the centred kernel feature space and gives an explicit formula for new points, so the mapping is fixed once fitted. t-SNE and UMAP optimise neighbourhood-preservation objectives and are designed mainly for visualisation; without extensions they do not provide a fixed mapping for new points. The better choice depends on whether a reusable feature mapping or a visual summary is the goal.

Can Kernel PCA reconstruct the original data?

Not directly. There is no closed-form pre-image in input space. Approximate pre-image methods, such as fixed-point iteration, exist, but they are iterative and can be unstable. If reconstruction is a primary requirement, autoencoders or variational autoencoders are the more usual choice.

How do I handle large datasets?

Exact Kernel PCA requires the full n × n kernel matrix, which becomes impractical as the sample size grows. The Nyström approximation uses a subset of landmark points to approximate the kernel matrix, reducing memory and computation relative to the full matrix. Random Fourier features give an explicit approximate feature map for shift-invariant kernels such as the RBF kernel. Both approaches trade some accuracy for scalability.

Related methods

Sources

  1. Schölkopf, B., Smola, A. J., & Müller, K.-R. (1998). Nonlinear component analysis as a kernel eigenvalue problem. Neural Computation, 10(5), 1299–1319.

    Open DOI reference
  2. Schölkopf, B., Smola, A. J., & Müller, K.-R. (1997). Kernel principal component analysis. In Artificial Neural Networks — ICANN'97, Lecture Notes in Computer Science, Vol. 1327, pp. 583–588. Springer.

    Open DOI reference
  3. Schölkopf, B., & Smola, A. J. (2002). Learning with Kernels: Support Vector Machines, Regularization, Optimization, and Beyond. MIT Press.

    ISBN: 978-0-262-19475-4