Generation

generate functionThu, 23 Mar 2023

k-means

data = np.random.randn(100, 2) def kmeans(data, k): # randomly initialize k centroids # initialize cluster assigments # loop until no centroid changes # calculate distances of all data points to each centroid # move the centroids to their new cluster's center of mass # reassign the data points to clusters pass

Want to kickstart your project?Use the new AI Studio to create your code