Skip to content

Instantly share code, notes, and snippets.

@ImadDabbura
Created September 17, 2018 16:53
Show Gist options
  • Save ImadDabbura/70a3fbcf17fba31aca6d393857e07314 to your computer and use it in GitHub Desktop.
Save ImadDabbura/70a3fbcf17fba31aca6d393857e07314 to your computer and use it in GitHub Desktop.
# Create horizantal data
X = np.tile(np.linspace(1, 5, 20), 2)
y = np.repeat(np.array([2, 4]), 20)
df = np.c_[X, y]
km = KMeans(n_clusters=2)
km.fit(df)
labels = km.predict(df)
centroids = km.cluster_centers_
fig, ax = plt.subplots(figsize=(6, 6))
plt.scatter(X, y, c=labels)
plt.xlim([0, 6])
plt.ylim([0, 6])
plt.text(5.1, 4, 'A', color='red')
plt.text(5.1, 2, 'B', color='red')
plt.text(2.8, 4.1, 'C', color='red')
ax.set_aspect('equal')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment