Exemplo n.º 1
0
#Loading data points from multiple files, for SSE error in whole dataset
#files = glob.glob(os.path.join(os.path.dirname(__file__), multiplefilepath + '*zscore.dat'))
#files.sort()
#        
#points = np.loadtxt(files[9])
#        
#cfiles = glob.glob(os.path.join(os.path.dirname(__file__), multiplefilepath + '*_initialcentroids*'))
#cfiles.sort()
#fninitcentroids = cfiles[9]





# run kmeans
km = KMeans(showsubplots=False)

initialMeans = np.zeros((k, len(points[0])))

minSSE = sys.maxint
minInitialMeans = np.zeros((k, len(points[0])))
minMeans = np.zeros((k, len(points[0])))
minLabels = np.zeros(len(points), dtype=int)



    
# initialize means
numOfExperiments = 5 #number of random initial means experiments
for count in xrange(numOfExperiments):
    if numOfExperiments == 1:
Exemplo n.º 2
0
import pylab
from km.kmeans import KMeans
from util.utilities import *


if __name__ == '__main__':   
    # kmeans for 3 clusters
    km = KMeans(showsubplots=False)
    k,d,i = 3, 0.1, 10
    data, centroids = Utils.generateTestDataAndCentroids(k, dimensions=2)
    means, labels = km.run(data, numberOfClusters=k, threshold=d, maxiterations=i)
    print "final means: \n%s" % means
    
    #if not subplot:
    Plot.plotPoints(data, labels, title='final means')
    Plot.plotMeans(means)
    pylab.show()