Created
December 19, 2013 09:11
-
-
Save rsimon/8036508 to your computer and use it in GitHub Desktop.
Clustering Hello World
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
Created on 02.05.2013 | |
@author: simonr | |
''' | |
from pylab import plot,show | |
from numpy import vstack,array | |
from numpy.random import rand | |
from scipy.cluster.vq import kmeans,vq | |
# data generation | |
data = vstack((rand(150,2) + array([.5,.5]),rand(150,2))) | |
# now with K = 3 (3 clusters) | |
centroids,_ = kmeans(data,3) | |
idx,_ = vq(data,centroids) | |
plot(data[idx==0,0],data[idx==0,1],'ob', | |
data[idx==1,0],data[idx==1,1],'or', | |
data[idx==2,0],data[idx==2,1],'og') # third cluster points | |
plot(centroids[:,0],centroids[:,1],'sm',markersize=8) | |
show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment