From 771cff75c08276b9129b0bcd07fe2808d0ac541e Mon Sep 17 00:00:00 2001 From: masaraed96 Date: Fri, 2 Jul 2021 14:08:13 +0200 Subject: [PATCH] suggesting easier way for plotting --- .../Section 24 - K-Means Clustering/kmeans.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/Machine Learning A-Z/Part 4 - Clustering/Section 24 - K-Means Clustering/kmeans.py b/Machine Learning A-Z/Part 4 - Clustering/Section 24 - K-Means Clustering/kmeans.py index f2dbd73..3054beb 100644 --- a/Machine Learning A-Z/Part 4 - Clustering/Section 24 - K-Means Clustering/kmeans.py +++ b/Machine Learning A-Z/Part 4 - Clustering/Section 24 - K-Means Clustering/kmeans.py @@ -40,12 +40,9 @@ y_kmeans = kmeans.fit_predict(X) # Visualising the clusters -plt.scatter(X[y_kmeans == 0, 0], X[y_kmeans == 0, 1], s = 100, c = 'red', label = 'Cluster 1') -plt.scatter(X[y_kmeans == 1, 0], X[y_kmeans == 1, 1], s = 100, c = 'blue', label = 'Cluster 2') -plt.scatter(X[y_kmeans == 2, 0], X[y_kmeans == 2, 1], s = 100, c = 'green', label = 'Cluster 3') -plt.scatter(X[y_kmeans == 3, 0], X[y_kmeans == 3, 1], s = 100, c = 'cyan', label = 'Cluster 4') -plt.scatter(X[y_kmeans == 4, 0], X[y_kmeans == 4, 1], s = 100, c = 'magenta', label = 'Cluster 5') -plt.scatter(kmeans.cluster_centers_[:, 0], kmeans.cluster_centers_[:, 1], s = 300, c = 'yellow', label = 'Centroids') +import seaborn as sb +clusters = [f'Cluster {i+1}' for i in y_means] +sb.scatterplot(x=X[:,0], y=X[:,1],hue=clusters) plt.title('Clusters of customers') plt.xlabel('Annual Income (k$)') plt.ylabel('Spending Score (1-100)')