Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save n0obcoder/e647ffd9e9e56f240a3475f3af26909b to your computer and use it in GitHub Desktop.
Save n0obcoder/e647ffd9e9e56f240a3475f3af26909b to your computer and use it in GitHub Desktop.
# finding the extremes of the data points so that this information
# could be used to initialize the k cluster centers within these extremes.
x_min= np.min(x_data)
x_max= np.max(x_data)
y_min= np.min(y_data)
y_max= np.max(y_data)
# we define a list of colors which could be used to represent data points assigned to different clusters.
color_list = ['Blue', 'Green', 'Yellow', 'Pink', 'Purple']
#set the value of 'k'
k= 3
# you can change the value of k upto 5 because the color_list that i have defined has only 5 colors.
# you can add more colors to the color_list and then change k to higher values.
# randomly initialize k number of center points within the extremes of the data points
kcenters = []
for i in range(k):
x_center= np.random.randint(x_min, x_max + 1)
y_center= np.random.randint(y_min, y_max + 1)
center = [x_center, y_center]
kcenters.append(center)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment