File Exchange

image thumbnail

Kernel PCA and Pre-Image Reconstruction

version 1.4 (6.9 MB) by

standard PCA, Gaussian kernel PCA, polynomial kernel PCA, pre-image reconstruction

13 Ratings



View License

In this package, we implement standard PCA, kernel PCA, and pre-image reconstruction of Gaussian kernel PCA. We also provide three demos: (1) Two concentric spheres embedding; (2) Face classification with PCA/kPCA; (3) Active shape models with kPCA.
Standard PCA is not optimized for very high dimensional data. But our kernel PCA implementation is very efficient, and has been used in many research projects.

Comments and Ratings (22)

Hi Wang, I have a small doubt. How do we define our own kernel here? I want to use an rbf kernel.


chen (view profile)

kumud arora

Why the test data kernel is not centralized??

Anamika jain

which type of data should be used to execute this code?


danhe (view profile)

what is the form of the database to use


phil (view profile)

Hi, Wang!
For several reasons, I need to do the KNN classifier after reducing the dimension of training and sampling data. When the type is guassian, it seems that the eigenvector will be complex number so that KNN is invaild. How can I solve this problem? Thanks so much.


Yan wang


mania (view profile)

please help us to do fault detection in nonlinear systems with kernel pca. because i'm a starter in this field.

Quan Wang

Quan Wang (view profile)

Hi Cheung,

If you compute ||a-b||, you will have to use loops. MATLAB loops are slow, and distanceMatrix avoids using loops, thus is very fast.



Cheung (view profile)


Quan Wang

Quan Wang (view profile)

Dear all,

We have updated the code and the document. The code now generates exactly the same results as shown in the document. I am sorry for the confusion in previous versions of this package. The current version has lots of significant improvements.


When running demo file why the 3rd fig is in 2d but not in 3d as plot3() is used to plot variable in 3d

Yan Ou

Yan Ou (view profile)


Siqi (view profile)

So Good!


Siqi (view profile)

Quan Wang

Beside, I myself am using this code package (v2.0) for a number of research projects. I am pretty sure the code works well and has been well optimized.

Quan Wang

Hi Kris. The "paper" (actually a course project report) was using unordered eigenvalues, while in the updated code I have decreasingly ordered eigenvalues. So the code is more "correct" in a scientific sense. If you want to generate the same results as the report, you can uncomment
"% eigValue=eigValue(1:min(size(X)));"
 in kPCA.m.

Hope this helps!

Kris Villez

Dear Quan Wang,

Thanks for sharing your code. However, I am not able to reproduce the results displayed in Figure 3 and 4 of your paper.

For Figure 3, it is not clear what the order of the applied polynomial is.

For Figure 4, the two features are highly correlated while the should in fact be uncorrelated. I wondered if this is a mistake in the paper or in the code.

Thanks for your comments,



Fixed a fatal bug in pre-image reconstruction.


addpath('../code') in demo2


We replaces all demos, and the data used for the demo. We also updated the document to provide better illustration and better experiments. Now the code generates exactly the same results as shown in the paper.


The efficiency is optimized.

MATLAB Release
MATLAB 8.0 (R2012b)

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video