mykmedoid.py - from matplotlib.image import imread import...

This preview shows page 1 out of 1 page.

from matplotlib.image import imreadimport matplotlib.pyplot as pltimport numpy as npfrom scipy.sparse import csc_matrixfrom PIL import Imagefrom scipy.spatial import distanceimport timedef mykmedoid(pixels,K):pixels = pixels.Tm = pixels.shape[1]d = pixels.shape[0]# find random medoids for K clustersc = pixels[:, np.random.randint(m,size=(1, K))[0]]iterations = 5print ("K-Medoid started ---")for i in range(iterations):print ("--iteration %d \n" % i)# E Step - Assigning label to each point O(N*K*i)c2 = np.sum(np.power(c,2), axis=0)tempdiff = (2*np.dot(pixels.T,c) - c2)labels = np.argmax(tempdiff, axis=1)clusters = {}for i in range(K):
End of preview. Want to read the entire page?

Upload your study docs or become a

Course Hero member to access this document

Term
Fall
Professor
Staff
Tags
K medoids, Medoid, Cnew, Assigning label

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture