Advertisement
lessientelrunya

plot3

Jun 28th, 2017
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.88 KB | None | 0 0
  1. from sklearn.cluster import KMeans
  2. k = 2 # Define the number of clusters in which we want to partion the data
  3. kmeans = KMeans(n_clusters = k) # Run the algorithm kmeans
  4. kmeans.fit(X);
  5. centroids = kmeans.cluster_centers_ # Get centroid's coordinates for each cluster
  6. labels = kmeans.labels_ # Get labels assigned to each data
  7. k = 2 # Define the number of clusters in which we want to partion the data
  8. kmeans = KMeans(n_clusters = k) # Run the algorithm kmeans
  9. kmeans.fit(X);
  10. centroids = kmeans.cluster_centers_ # Get centroid's coordinates for each cluster
  11. labels = kmeans.labels_ # Get labels assigned to each data
  12. colors = ['r.', 'g.'] # Define two colors for the plot below
  13. plt.figure()
  14. for i in range(len(X)):
  15.     plt.plot(X[i,0], X[i,1], colors[labels[i]], markersize = 30)
  16. plt.scatter(centroids[:,0],centroids[:,1], marker = "x", s = 300, linewidths = 5) # Plot centroids
  17. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement