Skip to content

Instantly share code, notes, and snippets.

@CharlesRajendran
Last active March 17, 2018 16:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CharlesRajendran/d586eb70b82b3dae4ba39397cd4a8423 to your computer and use it in GitHub Desktop.
Save CharlesRajendran/d586eb70b82b3dae4ba39397cd4a8423 to your computer and use it in GitHub Desktop.
#plot the scatters
'''
X[y_pred==0] - will list records which belongs to cluster 0
output:
Qty UnitPrice
1 1911 3.39
'''
plt.scatter(X[y_pred == 0].iloc[:, 0], X[y_pred == 0].iloc[:, 1], s=5, c="red")
plt.scatter(X[y_pred == 1].iloc[:, 0], X[y_pred == 1].iloc[:, 1], s=5, c="green")
plt.scatter(X[y_pred == 2].iloc[:, 0], X[y_pred == 2].iloc[:, 1], s=5, c="blue")
plt.scatter(X[y_pred == 3].iloc[:, 0], X[y_pred == 3].iloc[:, 1], s=5, c="purple")
# centroids X, Y Coordinates can be get through kmeans.cluster_centers_
plt.scatter(kmeans.cluster_centers_[:, 0], kmeans.cluster_centers_[:, 1], s=100, c="black", marker="*")
# I limit the y value to get rid of the outlier records
plt.ylim([0,20])
plt.xlabel("Sold Quantity")
plt.ylabel("Unit Price")
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment