Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from copy import deepcopy
- import numpy
- from matplotlib import pyplot
- import random
- import math
- import seaborn
- from sklearn.cluster import KMeans
- from sklearn import datasets
- from sklearn.datasets import make_blobs
- X, temp = make_blobs(n_samples=200, centers=30)
- # n_samples określa liczbę punktów
- # centers liczbę centrów
- # X zawiera listę punktów
- # y centra, do jakiego należy punkt podczas generowania (nie trzeba z nich korzystać podczas działania tego programu) -
- km = KMeans(
- n_clusters=3, init='random',
- )
- temp_km = km.fit_predict(X)
- #print(temp_km)
- pyplot.scatter(
- km.cluster_centers_[:, 0], km.cluster_centers_[:, 1],
- s=200, marker='o',
- c='black', edgecolor='black',
- label='Centra klastrow'
- )
- pyplot.scatter(
- X[temp_km == 0,0], X[temp_km == 0, 1],
- c="red",
- label="Klaster 1"
- )
- pyplot.scatter(
- X[temp_km == 1,0], X[temp_km == 1, 1],
- c="blue",
- label="Klaster 2"
- )
- pyplot.scatter(
- X[temp_km == 2,0], X[temp_km == 2, 1],
- c="pink",
- label="Klaster 3"
- )
- pyplot.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement