Last active
March 17, 2018 16:15
-
-
Save CharlesRajendran/d586eb70b82b3dae4ba39397cd4a8423 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
#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