Created
April 28, 2011 09:05
-
-
Save dwinter/946053 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import numpy as np | |
from scipy import cluster | |
from matplotlib import pyplot | |
#fake some data | |
tests = np.reshape( np.random.uniform(0,100,60), (30,2) ) | |
#plot remaining variance for each value for 'k' between 1,10 | |
initial = [cluster.vq.kmeans(tests,i) for i in range(1,10)] | |
pyplot.plot([var for (cent,var) in initial]) | |
pyplot.show() | |
#pick a winner | |
cent, var = initial[3] | |
#use vq() to get as assignment for each obs. | |
assignment,cdist = cluster.vq.vq(tests,cent) | |
pyplot.scatter(tests[:,0], tests[:,1], c=assignment) | |
pyplot.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment