Created
May 20, 2019 04:56
-
-
Save ahmdrz/b21163dfc107622c2a8de24f07ccd389 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
from sklearn.cluster import KMeans | |
import matplotlib.pyplot as plt | |
first_random = -2 * np.random.rand(100, 2) | |
second_random = 1 + 2 * np.random.rand(50, 2) | |
dataset = np.concatenate((first_random, second_random)) | |
plt.scatter(dataset[:, 0], dataset[:, 1]) | |
plt.show() | |
model = KMeans(n_clusters=2) | |
model.fit(dataset) | |
centers = model.cluster_centers_ | |
plt.scatter(dataset[:, 0], dataset[:, 1], s=50, c='b') | |
plt.scatter(centers[0][0], centers[0][1], s=200, c='r') | |
plt.scatter(centers[1][0], centers[1][1], s=200, c='r') | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment