Created
July 15, 2020 11:36
-
-
Save jose-ramirez/135f7b77fd885086a71a5388d3de9478 to your computer and use it in GitHub Desktop.
This file contains 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
from matplotlib import pyplot as plt | |
from sklearn.datasets import make_blobs | |
from sklearn.cluster import KMeans | |
X, y = make_blobs(n_samples=500, centers=20, random_state=999) | |
plt.scatter(X[:,0], X[:,1]) | |
kmeans = KMeans(n_clusters=4, init='k-means++', max_iter=300, n_init=10) | |
y_preds = kmeans.fit_predict(X) | |
centroids = kmeans.cluster_centers_ | |
plt.scatter(X[:, 0], X[:, 1], c=y_preds) | |
plt.scatter(centroids[:, 0], centroids[:, 1], s=50, c='red') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment