Level 0: Foundation
★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.PCA after bending the space
PCA can only find straight directions. Two rings, one inside the other, have no straight direction that separates them. Kernel PCA first imagines the data mapped into a much richer space, where “distance from the centre” becomes a coordinate, and does PCA there. It never computes that space explicitly; it only needs a kernel, a similarity between every pair of points. The result is a few new coordinates that can unfold curved structure.
Many engineering data sets have nonlinear structure: operating envelopes, limit cycles, curved degradation paths. Kernel PCA gives nonlinear features and monitoring statistics (kernel-PCA T² and SPE for process monitoring) using only a similarity measure, and it sits at the heart of kernel methods in general.
- 1. Kernel PCA needs…
- 2. With a linear kernel, kernel PCA equals…
- 3. In the demo, separating the rings needed γ that is…
Level 1: Beginner
★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.The pieces by hand
RBF kernel. k(x, y) = exp(−γ‖x − y‖²). At distance 1 with γ = 0.5, k = e^(−0.5) = 0.607. A point with itself gives 1.
Polynomial kernel. k(x, y) = (xᵀy + 1)². For x = (1, 2): k(x, x) = (5 + 1)² = 36. With y = (0, 1): (2 + 1)² = 9.
Centring in feature space. Feature vectors must be centred, but they are never computed. Centre the kernel matrix instead: K_c = J K J, with J = I − (1/n)11ᵀ. For K = [[2, 1], [1, 2]]: K_c = [[0.5, −0.5], [−0.5, 0.5]]. Its rows and columns sum to 0.
Eigenvectors and scores. If K_c v = λv, then
- the training scores on that component are √λ·v;
- the projection coefficients α = v/√λ make the feature-space direction have unit length.
For λ = 4 and v = (1, 0): α = (0.5, 0).
The steps in plain English:
- Choose a kernel and its parameters (RBF γ, polynomial degree).
- Build the n × n kernel matrix K and double-centre it.
- Eigendecompose K_c and keep the top k eigenpairs. Scale the eigenvectors to α = v/√λ.
- Project a new point: compute its kernel with every training point, centre that row consistently with the training centring, and multiply by α.
- 1. RBF kernel value of a point with itself?
- 2. Rows of the centred kernel matrix sum to…
- 3. Training scores on a component with eigenvalue λ and eigenvector v are…
Level 2: Intermediate
★★★☆☆ Intermediate⏱ 30 minUndergraduate students and practising engineers.Derivation, centring and the width problem
Derivation. PCA in feature space solves C_φ w = λw, with C_φ = (1/n)Σφ(xᵢ)φ(xᵢ)ᵀ. Every solution lies in the span of the φ(xᵢ): w = Σαᵢφ(xᵢ). Substituting and multiplying by φ(x_j)ᵀ gives K_c α = nλα, an n × n eigenproblem that uses only kernel values (Schölkopf, Smola and Müller, 1998).
Normalising wᵀw = αᵀK_cα = 1 gives α = v/√(eigenvalue). The projection of φ(x) on w is Σαᵢ k_c(xᵢ, x).
Checks (exercise 1).
- With the linear kernel k = xᵀy, kernel PCA reproduced ordinary PCA scores exactly.
- With an RBF kernel (γ = 0.5) on two concentric rings, one kernel component separated the rings perfectly by a single threshold.
- Out-of-sample projection placed slightly shifted points next to the originals.
The width γ controls everything.
- Small γ: the RBF kernel is close to 1 − γ‖x − y‖² + …, so the leading components behave like low-order polynomial features.
- Large γ: the kernel matrix approaches the identity, each point is similar only to itself, the components fragment, and new points project to almost zero.
Exercise 2 (a linear classifier on the kernel-PCA features):
- with only 2 components, the rings needed γ ≈ 1 (test accuracy 0.87), and small γ failed;
- with 10 components, every γ from 0.01 to 3 reached 100%;
- the largest γ (100) failed everywhere.
Cost. O(n²) memory and O(n³) for the eigendecomposition, impractical beyond tens of thousands of points. Nyström or random-Fourier-feature approximations reduce it to O(nm²) with m landmarks.
Pre-images. Kernel-PCA reconstructions live in feature space; mapping them back to input space needs an approximate pre-image, such as Mika et al.’s fixed-point iteration for RBF kernels. This matters for kernel-PCA denoising.
from sklearn.decomposition import KernelPCA
kp = KernelPCA(n_components=10, kernel="rbf", gamma=0.5, fit_inverse_transform=True).fit(X_train)
Z = kp.transform(X_new); X_back = kp.inverse_transform(Z) # learned approximate pre-image- 1. Kernel PCA reduces to an eigenproblem of size…
- 2. Very large γ in an RBF kernel makes K close to…
- 3. Mapping kernel-PCA reconstructions back to input space is the…
Level 3: Advanced
★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.Theory
Mercer kernels. A symmetric function k is a valid kernel exactly when every kernel matrix it produces is positive semidefinite; then it equals an inner product in some (possibly infinite-dimensional) feature space. The RBF kernel’s feature space is infinite-dimensional, so kernel PCA can find up to n − 1 components, regardless of the input dimension.
Out-of-sample centring. A new point’s kernel row must be centred with the training means:
k_c(x) = k(x) − 1ₙᵀK/n − (k(x)ᵀ1/n)1 + (1ᵀK1/n²)1.
Re-centring it on its own would shift the projection.
Relation to other methods. Kernel PCA with particular data-dependent kernels reproduces MDS, Isomap, LLE and Laplacian eigenmaps (Ham et al., 2004). The difference between those methods is the kernel, or equivalently the similarity graph they build.
Interview questions.
- When would you use kernel PCA? For nonlinear structure at moderate n, as nonlinear features for a downstream model, or for nonlinear process monitoring. For visualising large data sets, t-SNE or UMAP are usually better, and Nyström approximations scale kernel PCA.
- How do you choose γ? Use the median heuristic (γ = 1/median pairwise squared distance) as a start, then cross-validate on the downstream task. Kernel-PCA variance shares are not comparable across γ.
- 1. A valid (Mercer) kernel produces kernel matrices that are…
- 2. Maximum number of kernel components with n training points (centred)?
- 3. Isomap and LLE can be seen as kernel PCA with…
Level 4: Expert
★★★★★ Expert⏱ 25 minResearchers: original papers and open problems.Which matters more: γ or the number of components?
History.
- B. Schölkopf, A. Smola and K.-R. Müller introduced kernel PCA (1997, 1998).
- S. Mika et al. (1999) proposed kernel-PCA denoising with pre-images.
- C. Williams and M. Seeger (2001) introduced the Nyström approximation for kernel machines.
- J. Ham, D. Lee, S. Mika and B. Schölkopf (2004) gave the kernel view of manifold learning.
Exercise 2. Test accuracy of a least-squares linear classifier on the first m kernel-PCA features (RBF kernel), 200 training and 100 test points, 3 splits.
| γ | 0.01 | 0.03 | 0.1 | 0.32 | 1 | 3.2 | 10 | 32 | 100 |
|---|---|---|---|---|---|---|---|---|---|
| rings, m = 2 | 0.47 | 0.47 | 0.45 | 0.54 | 0.87 | 0.73 | 0.66 | 0.60 | 0.54 |
| rings, m = 10 | 1.00 | 1.00 | 1.00 | 1.00 | 1.00 | 1.00 | 0.95 | 0.83 | 0.58 |
| moons, m = 2 | 0.89 | 0.89 | 0.89 | 0.89 | 0.84 | 0.81 | 0.82 | 0.74 | 0.62 |
| moons, m = 10 | 0.99 | 0.99 | 0.99 | 0.99 | 1.00 | 1.00 | 0.99 | 0.97 | 0.81 |
- With enough components, γ hardly mattered over three decades. Small-γ RBF components act like polynomial features, and 10 of them already include the radius-like feature that separates the rings.
- With only 2 components, γ had to be tuned to put the separating direction into the top two.
- Very large γ always failed out of sample. Test points are then dissimilar to every training point, so their projections collapse toward 0. That is overfitting in kernel space.
Kernel PCA in AI, robotics and aerospace
- Nonlinear process monitoring: kernel-PCA T² and SPE statistics for systems with curved normal-operation manifolds.
- Feature extraction for classifiers on sensor or image data where linear PCA misses structure.
- Denoising signals and shapes via kernel-PCA projection and pre-images.
References
- B. Schölkopf, A. Smola, K.-R. Müller (1998). “Nonlinear component analysis as a kernel eigenvalue problem.” Neural Computation 10(5).
- S. Mika, B. Schölkopf, A. Smola, K.-R. Müller, M. Scholz, G. Rätsch (1999). “Kernel PCA and de-noising in feature spaces.” NeurIPS 11.
- C. K. I. Williams, M. Seeger (2001). “Using the Nyström method to speed up kernel machines.” NeurIPS 13.
- J. Ham, D. D. Lee, S. Mika, B. Schölkopf (2004). “A kernel view of the dimensionality reduction of manifolds.” Proc. ICML.
- J.-M. Lee, C. Yoo, S. W. Choi, P. A. Vanrolleghem, I.-B. Lee (2004). “Nonlinear process monitoring using kernel principal component analysis.” Chemical Engineering Science 59.