Code covered by the BSD License  

Highlights from
Kernel k-means

4.0

4.0 | 2 ratings Rate this file 69 Downloads (last 30 days) File Size: 17.33 KB File ID: #26182
image thumbnail

Kernel k-means

by Mo Chen

 

23 Dec 2009 (Updated 03 Feb 2012)

kernel k-means algorithm

| Watch this File

File Information
Description

This function performs kernel version of kmeans algorithm. When the linear kernel (i.e., inner product) is used, the algorithm is equivalent to standard kmeans algorithm.

Input
K: n x n a semi-definite matrix computed by a kernel function on all sample pairs
m: the number of clusters k (1 x 1) or the initial label of samples (1 x n, 1<=label(i)<=k)

reference: [1] Kernel Methods for Pattern Analysis
by John Shawe-Taylor, Nello Cristianini

sample code:
load data;
K=x'*x; % use linear kernel
label=knkmeans(K,3);
spread(x,label)

MATLAB release MATLAB 7.9 (2009b)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (9)
11 Feb 2010 Mathieu

It seems that if I request N clusters, the algorithms outputs k clusters, k<=N clusters and most of the time k<<N. I was wondering if this is by construction. If yes, could provide me with an explanation ?

11 Feb 2010 Mo Chen

This happens for standard kmeans too, which is caused by the nature of the algorithm. The reason is that when you set a very big number for k, after several iterations, some clusters might become empty.

23 Feb 2010 Mathieu

I see, reading the code I do not manage to understand what are the principles behind the algorithm. Do you have a reference that I could get from the web or do you advise to buy the book ?

23 Feb 2010 Seyed Salim

Mathieu, you can refer to machine learning and pattern recognition by Bishop, 2005. Alternatively this is for free: www-stat.stanford.edu/~hastie/Papers/ESLII.pdf

20 Mar 2010 Mo Chen

Hi mathieu,
As indicated in the description, this algorithm is explained in
reference: [1] Kernel Methods for Pattern Analysis
by John Shawe-Taylor, Nello Cristianini

15 Nov 2010 John Melonakos

The code appears broken to me:

>> load data;
K=x'*x; % use linear kernel
label=knkmeans(K,3);
scatterd(x,label)
??? Undefined function or variable 'val'.

Error in ==> knkmeans at 31
energy = sum(val)+trace(K);

11 Apr 2011 Phillip

Hello I encountered the same problem as john luckily i had the book, I added the following code. The energy is the sum squared clustering cost function. I have been optimizing my kernel hyper-parameters to minimise this energy. Been working fairly well so thanks. Not an expert so could be wrong.

A=zeros(size(S'));
for i=1:1:size(K,1)
          A(i,label(i))=1;
end
D=diag(1./sum(A));
  energy = trace(K)-trace(sqrt(D)*A'*K*A*sqrt(D));

10 Jan 2012 Mo Chen

Hi, Phillip,
You computation is right, only not very efficient. Check my new code

02 Apr 2012 Santiago  
Please login to add a comment or rating.
Updates
25 Dec 2009

add sample data and detail description

30 Sep 2010

remove empty clusters

03 Feb 2012

fix a minor bug of returning energy

03 Feb 2012

Improve the code and fix a bug of returning energy

Tag Activity for this File
Tag Applied By Date/Time
kernel Mo Chen 23 Dec 2009 16:05:37
kmeans Mo Chen 23 Dec 2009 16:05:37
clustering Mo Chen 23 Dec 2009 16:05:37
nonlinear Mo Chen 28 Dec 2009 10:37:43
kernel Phillip 17 Apr 2011 03:23:35
kmeans Samisaid 07 May 2011 06:58:09
kernel Love 29 Apr 2012 14:34:22
kmeans Love 29 Apr 2012 14:36:49

Contact us at files@mathworks.com