Skip to content

Instantly share code, notes, and snippets.

@briverse17
Created December 23, 2019 16:20
Show Gist options
  • Save briverse17/8195b9411f2990b874c0f9e15608a4ed to your computer and use it in GitHub Desktop.
Save briverse17/8195b9411f2990b874c0f9e15608a4ed to your computer and use it in GitHub Desktop.
new_medoids = []
for i in range(0, self.k):
new_medoid = self.medoids[i]
old_medoids_cost = self.medoids_cost[i]
for j in range(len(clusters[i])):
#Cost of the current data points to be compared with the current optimal cost
cur_medoids_cost = 0
for dpoint_index in range(len(clusters[i])):
cur_medoids_cost += euclideanDistance(clusters[i][j], clusters[i][dpoint_index])
#If current cost is less than current optimal cost,
#make the current data point new medoid of the cluster
if cur_medoids_cost < old_medoids_cost:
new_medoid = clusters[i][j]
old_medoids_cost = cur_medoids_cost
#Now we have the optimal medoid of the current cluster
new_medoids.append(new_medoid)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment