Guest User

Untitled

a guest
Jul 23rd, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3. from matplotlib import style
  4. from sklearn.cluster import KMeans
  5.  
  6. X = np.array([[1,2],
  7. [5,8],
  8. [1.5,1.8],
  9. [8,8],
  10. [1,0.6],
  11. [9,11]])
  12.  
  13. kmeans = KMeans(n_clusters = 2)
  14. kmeans.fit(X)
  15.  
  16. centroids = kmeans.cluster_centers_
  17. labels = kmeans.labels_
  18.  
  19. print(centroids)
  20. print(labels)
  21.  
  22. colors = ["g.","r."]
  23.  
  24. for i in range(len(X)):
  25. print("coordinates:",X[i], "label:",labels[i])
  26. plt.plot(X[i][0], X[i][1], colors[labels[i]], markersize = 10)
  27.  
  28.  
  29. plt.scatter(centroids[:, 0],centroids[:, 1], marker = "x", s=150, linewidths = 5, zorder = 10)
  30. plt.show()
Add Comment
Please, Sign In to add comment