MCPcopy Index your code
hub / github.com/TheAlgorithms/Python / revise_centroids

Function revise_centroids

machine_learning/k_means_clust.py:95–105  ·  view source on GitHub ↗
(data, k, cluster_assignment)

Source from the content-addressed store, hash-verified

93
94
95def revise_centroids(data, k, cluster_assignment):
96 new_centroids = []
97 for i in range(k):
98 # Select all data points that belong to cluster i. Fill in the blank (RHS only)
99 member_data_points = data[cluster_assignment == i]
100 # Compute the mean of the data points. Fill in the blank (RHS only)
101 centroid = member_data_points.mean(axis=0)
102 new_centroids.append(centroid)
103 new_centroids = np.array(new_centroids)
104
105 return new_centroids
106
107
108def compute_heterogeneity(data, k, centroids, cluster_assignment):

Callers 1

kmeansFunction · 0.85

Calls 1

appendMethod · 0.45

Tested by

no test coverage detected