예제 #1
0
plot(x,y,'ok')
savefig('obs_space.png')
close()
size = len(obs)
size = size
print '%0.1f data points'%size
t0 = time.clock()
#threshold = linspace(0.01,0.1,10)
#k_list = []
#for t in threshold:
#    labels,k,centroids = ksmeans(obs,threshold[t],100)
#    k_list.append(k) 
#figure()
#hist(k_list)
#show()
labels,k,centroids = ksmeans(obs,0.1,100)
process = time.clock() - t0
print 'Process time: %0.2f secs'%process

#a = [0,0]
#b = [0,0]
#acc_array = zeros((clusters,k))
#for l in range(clusters):
#    for m in range(k):
#        for n in range(len(obs[cls_labels == l])):
#            for o in range(len(obs[labels == m])):
#                a[0] = obs[cls_labels == l][n,0]
#                a[1] = obs[cls_labels == l][n,1]
#                b[0] = obs[labels == m][o,0]
#                b[1] = obs[labels == m][o,1]
#                if a == b:
예제 #2
0
import pylab
from scipy import io
from numpy import *
import scipy
from ksmeans import ksmeans
import time

# mat = io.loadmat('digits_full.mat')
# digit_data = mat['digits']
digit_data = loadtxt("pendigits.csv", delimiter=",")
print shape(digit_data)

size = shape(digit_data)
size = size[0] * size[1]
t0 = time.clock()
labels, k, centers = ksmeans(digit_data, 0.05, 100)
process = time.clock() - t0
print "Process time: %0.2f secs" % process
print "%0.1f data points" % size
print k

savetxt("digits_labels.txt", labels)