Skip to content

Instantly share code, notes, and snippets.

@ImadDabbura
Created September 17, 2018 16:54
Show Gist options
  • Save ImadDabbura/e7be63d444863ef950381a81b3e43009 to your computer and use it in GitHub Desktop.
Save ImadDabbura/e7be63d444863ef950381a81b3e43009 to your computer and use it in GitHub Desktop.
# Cricles
X1 = make_circles(factor=0.5, noise=0.05, n_samples=1500)
# Moons
X2 = make_moons(n_samples=1500, noise=0.05)
fig, ax = plt.subplots(1, 2)
for i, X in enumerate([X1, X2]):
fig.set_size_inches(18, 7)
km = KMeans(n_clusters=2)
km.fit(X[0])
labels = km.predict(X[0])
centroids = km.cluster_centers_
ax[i].scatter(X[0][:, 0], X[0][:, 1], c=labels)
ax[i].scatter(centroids[0, 0], centroids[0, 1], marker='*', s=400, c='r')
ax[i].scatter(centroids[1, 0], centroids[1, 1], marker='+', s=300, c='green')
plt.suptitle('Simulated data', y=1.05, fontsize=22, fontweight='semibold')
plt.tight_layout()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment