Code covered by the BSD License  

Highlights from
K-medoids

3.875
3.9 | 8 ratings Rate this file 99 Downloads (last 30 days) File Size: 32.4 KB File ID: #28898
image thumbnail

K-medoids

by

Mo Chen (view profile)

 

30 Sep 2010 (Updated )

K-medoids clustering algorithm

| Watch this File

File Information
Description

Efficient implementation of K-medoids clustering methods. http://en.wikipedia.org/wiki/K-medoids

It is usually more robust than kmeans algorithm.

try
load data;
label=kmedoids(x,3);
spread(x,label);

Input data are assumed COLUMN vectors!
You can only visualize 2d data!

Acknowledgements

This file inspired Parallel Coordinate Plots Gui Toolbox.

MATLAB release MATLAB 8.2 (R2013b)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (16)
19 May 2014 Eelke Spaak

Even though the code is lightning fast, the solution is not the proper one, hence this code is useless. See http://i.imgur.com/VNY73l7.png for example output of k = 6 for a naive (and very slow) implementation of the algorithm, and this submission. Obviously the naive is correct, this submission is incorrect.

Nonetheless thanks for the effort! It would be great if you could produce correct code that is still as fast.

02 May 2014 Yuanjun Xiong  
05 Apr 2014 kalarmago  
05 Apr 2014 kalarmago

I tested calling to kmedoids() function, it always returns
label = 2 1
energy = 0
index = 2 1
I believe it does not work. Thanks anyway.

Comment only
03 Apr 2014 SU Li

SU Li (view profile)

Nice code. Very helpful. However, if the number of input data is large, then the D matrix is too large (n^2) which may make memory overflow.

Comment only
03 Apr 2014 Joao Henriques

Simple and elegant code, thanks!

23 Dec 2013 Tong

Tong (view profile)

If I want to use the cosine distance between two vectors, What shold I do?

26 Nov 2013 MUSA

MUSA (view profile)

 
08 Oct 2013 kannan

kannan (view profile)

if i want to apply kmedoids agorithm for X data in function [label, energy, index] = kmedoids(X,k) 3599*11 size data then it is not working properly can anybody of you give idea for this?

Comment only
27 Aug 2013 Nejc Ilc

Very compact and efficient coding. Nice job!
However, there is an error when k=1. I suggest to add the third parameter (dimension) to the calls of function min:
(Line 8): [~, label] = min(D(randsample(n,k),:),[],1);
(Line 11): [~, label] = [~, index] = min(D*sparse(1:n,label,1,n,k,n),[],1);

13 Dec 2012 Tu

Tu (view profile)

Not working for my data as well.
My data was of the dimension 17-by-71.
wanted to find 4 or 6 clusters.
and spread did not work.

swaheed.iu@gmail.com

Comment only
24 May 2012 Graeme

Graeme (view profile)

Undefined function 'randsample' for input arguments of type 'double'.

Error in kmedoids (line 8)
[~, label] = min(D(randsample(n,k),:));

Comment only
09 Apr 2012 huang

huang (view profile)

 
20 Mar 2012 Mo Chen

Mo Chen (view profile)

better post your error message

Comment only
18 Mar 2012 Dinusha Rathnayaka

Dear Sir Pls help!!! My Matlab version is Matlab7.6.0..Is this the reason?
Pls reply when you free!!!

Comment only
18 Mar 2012 Dinusha Rathnayaka

SIMPLY NOT working.
load data;
label=kmedoids(x,3);
spread(x,label);.

Comment only
Updates
04 Feb 2012

significantly simplify the code

15 Feb 2012

correct description

17 Oct 2013

fix bug for k=1

Contact us