View License

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

» Watch video

Highlights from
Kernel PCA

4.5 | 11 ratings Rate this file 82 Downloads (last 30 days) File Size: 2.17 KB File ID: #27319 Version: 1.0
image thumbnail

Kernel PCA


Ambarish Jash (view profile)


Non-linear dimension reduction using kernel PCA.

| Watch this File

File Information

This technique takes advantage of the kernel trick that can be used in PCA. This is a tutorial only and is slow for large data sets.
In line 30 the kernel can be changed. Any Kernel should do it.
Ref :

MATLAB release MATLAB 7.9 (R2009b)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (21)
20 Dec 2016 Ali Algomae

Dear expert,
i want to ask i used this package to do reduction for (140*70112) the output is(140*139)
my question is it necessary that the values in(140*139) are the same values in(140*70112) or not?

15 Nov 2016 Rui Fairy

can you give me some trainning sets?

18 Aug 2016 anumala udayeni

i tried this code for my data set of size 400x2048.2048 dimensions and 400 observations.the results were not code.won't it work for large data?what should i do for best solution.i have to reduce my data to 220 dimensions.any help please..

Comment only
24 Jun 2016 sailer

sailer (view profile)


20 Jun 2016 Jack Sparrow

Thank you for this program. it really help me a lot to design my algorithm.

27 Nov 2015 Ivo

Ivo (view profile)

I agree with Enriques corrections. But Line 61 should be as follows:
eigvec(:,i) = sqrt(1/(eigval(i)*(eigvec(:,i)'*eigvec(:,i))))*eigvec(:,i);

20 Aug 2015 NN

NN (view profile)


Comment only
16 Feb 2015 ait mohamed linda

the data base have the attributs and classe ?what is the form of the database to use

13 Oct 2013 chen

chen (view profile)

Thank you for your file,it's great!

Comment only
22 Sep 2013 Pei-feng


28 Sep 2011 BigZero

I think there are some mistake in this implementation, the last step the feature vector feature dimension reduction procedure is incorrect, since you can not do it in this way. If you do it in this way, how can you tell the difference between PCA and KPCA. we should do it by using inner product form.

Comment only
02 Sep 2011 Md. Ali Hossain

I am unable to run the algorithm for large data set. I am working on hyperspectral image of size 191x370856. What can I do and what is the best solution.

Comment only
14 Aug 2011 Natalie

Sorry Enrique I don't understand your second point. Surely it doesn't matter whether you normalize just the non-zero eigenvalues or all of the eigenvalues since the non-zero eigenvalues won't change the projections? Have I missed something? Thanks.

Comment only
11 Jun 2011 rem

rem (view profile)

I used this code for face recognition, i chosed Gaussian kernel and ploynominal kernel, but i have not seen any improvement over Eigenface.

Comment only
27 Apr 2011 Weizhi Li

08 Apr 2011 Sanjay

Sanjay (view profile)

I used your algorithm and works fine, i have taken the entire data that is 5x3000 and after simulation i got new data, can i use this new data for Support vector regression.

please advise

Comment only
10 Feb 2011 Kasper Marstal

Thank you for a great submission Ambarish, helped a lot to figure out Schölkopf's "Nonlinear Component Analysis as a Kernel Eigenvalue

And thank for dear comments Enrique, I have thought alot about 1) and 2) as well but was afraid I was the one mistaken as you often are when learning new stuff.

Thanks a bunch you two!

18 Jan 2011 Enrique Corona

Sorry about my last two blank comments. Mouse double-click errors.

Very nice code! However I have a couple of subtle comments:

1) When you center the Kernel matrix be sure to divide the "ones" matrix by the number of samples i.e.
Line 43: one_mat = ones(size(K));
should read
Line 43: one_mat = ones(size(K))./size(data_in,2);

2) Eigenvector normalization implies dividing each of the columns of the eigenvector matrix by the sqrt of its corresponding eigenvalue. Do so by substituting:
Line 61: eigvec(:,col) = eigvec(:,col)./(sqrt(eig_val(col,col)));
to read
Line 61: eigvec(:,col) = eigvec(:,col)./(sqrt(eigval(col,col)));

3) Also, if you must do eigenvalue sorting, be careful to use only the diagonal of the "Lambda" matrix and not the whole matrix. Use:

Line 63: [dummy, index] = sort(diag(eigval),'descend');
instead of
Line 63: [dummy, index] = sort(eig_val,'descend');

You can also see "Learning with Kernels" by B. Scholkopf and A. Smola, Section 14.2 (particularly eqs 14.14 and 14.17). Hope this is helpful.

18 May 2010 Ambarish Jash

Ambarish Jash (view profile)

Lexander try [aa,index] = sort(eig_val,'descend');
clear aa
% May be you cannot ignore the output from sort.

Comment only
13 May 2010 Alexander Patrushev

I use Matlab 2008 (7.6) and there is error at this line:
[~, index] = sort(eig_val,'descend');
Expression or statement is incorrect--possibly unbalanced (, {, or [.

How could I fix that?

Comment only
13 May 2010 Alexander Patrushev

Good example!

Contact us