diff Marea/marea_cluster.py @ 31:944e15aa970a draft

Uploaded
author bimib
date Tue, 15 Oct 2019 12:22:43 -0400
parents e6831924df01
children abf0bfe01c78
line wrap: on
line diff
--- a/Marea/marea_cluster.py	Tue Oct 15 12:21:16 2019 -0400
+++ b/Marea/marea_cluster.py	Tue Oct 15 12:22:43 2019 -0400
@@ -176,6 +176,10 @@
     scores = []
     all_labels = []
     
+    clusterer = KMeans(n_clusters=1, random_state=10)
+    distortions.append(clusterer.fit(dataset).inertia_)
+    
+    
     for n_clusters in range_n_clusters:
         clusterer = KMeans(n_clusters=n_clusters, random_state=10)
         cluster_labels = clusterer.fit_predict(dataset)
@@ -227,8 +231,10 @@
     
 def elbow_plot (distortions, k_min, k_max):
     plt.figure(0)
-    plt.plot(range(k_min, k_max+1), distortions, marker = 'o')
-    plt.xlabel('Number of cluster')
+    x = list(range(k_min, k_max + 1))
+    x.insert(0, 1)
+    plt.plot(x, distortions, marker = 'o')
+    plt.xlabel('Number of clusters (k)')
     plt.ylabel('Distortion')
     s = 'clustering/elbow_plot.png'
     fig = plt.gcf()