title: K-means Clustering in Python
body: <pre><code>import numpy as np
  import matplotlib.pyplot as plt
  from sklearn.cluster import KMeans
  
  
  x = [916,684,613,612,593,552,487,484,475,474,438,431,421,418,409,391,389,388,
      380,374,371,369,357,356,340,338,328,317,316,315,313,303,283,257,255,254,245,
      234,232,227,227,222,221,221,219,214,201,200,194,169,155,140]
  
  kmeans = KMeans(n_clusters=4)
  a = kmeans.fit(np.reshape(x,(len(x),1)))
  centroids = kmeans.cluster_centers_
  
  labels = kmeans.labels_
  
  print(centroids)
  print(labels)
  
  colors = ["g.","r.","y.","b."]
  
  for i in range(len(x)):
      plt.plot(x[i], colors[labels[i]], markersize = 10)
  
  plt.scatter(centroids[:, 0], marker = "x", s = 150, linewidths = 5, zorder = 10)
  plt.show()
  </code></pre>
  
  <p>The code above displays 4 clusters, but they are definitely not something I want to have. </p>
  
  <p>I also get an error, which makes it even worst. The output I get is in the picture below. </p>
  
  <p>The error I get is: <code>TypeError: scatter() missing 1 required positional argument: 'y'</code> Error is not a big deal because I don't like what I have anyways. </p>
  
  <p><a href="https://i.stack.imgur.com/9j85h.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/9j85h.png" alt="Clusters Output"></a></p>
  
  <p>Following is the image of how I want my output of clusters to look like. </p>
  
  <p><a href="https://i.stack.imgur.com/g7dDI.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/g7dDI.png" alt="Cluster I want"></a></p>