Advertisement
pkowalecki

175IC_5.3

Dec 7th, 2019
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.06 KB | None | 0 0
  1. from copy import deepcopy
  2. import numpy
  3. from matplotlib import pyplot
  4. import random
  5. import math
  6. import seaborn
  7. from sklearn.cluster import KMeans
  8. from sklearn import datasets
  9. from sklearn.datasets import make_blobs
  10.  
  11. X, temp = make_blobs(n_samples=200, centers=30)
  12. # n_samples określa    liczbę punktów
  13. # centers   liczbę centrów
  14. # X zawiera listę  punktów
  15. # y centra, do  jakiego należy punkt   podczas generowania (nie    trzeba  z   nich    korzystać  podczas działania  tego    programu)   -
  16. km = KMeans(
  17.     n_clusters=3, init='random',
  18. )
  19. temp_km = km.fit_predict(X)
  20. #print(temp_km)
  21. pyplot.scatter(
  22.     km.cluster_centers_[:, 0], km.cluster_centers_[:, 1],
  23.     s=200, marker='o',
  24.     c='black', edgecolor='black',
  25.     label='Centra klastrow'
  26. )
  27.  
  28. pyplot.scatter(
  29.     X[temp_km == 0,0], X[temp_km == 0, 1],
  30.     c="red",
  31.     label="Klaster 1"
  32. )
  33. pyplot.scatter(
  34.     X[temp_km == 1,0], X[temp_km == 1, 1],
  35.     c="blue",
  36.     label="Klaster 2"
  37. )
  38. pyplot.scatter(
  39.     X[temp_km == 2,0], X[temp_km == 2, 1],
  40.     c="pink",
  41.     label="Klaster 3"
  42. )
  43. pyplot.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement