Advertisement
korenizla

Untitled

Jan 23rd, 2023
294
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.32 KB | None | 0 0
  1. distortions = []
  2. K = range(1,10)
  3. for k in K:
  4.     kmeanModel = KMeans(n_clusters=k)
  5.     kmeanModel.fit(X)
  6.     distortions.append(kmeanModel.inertia_)
  7.  
  8. plt.figure(figsize=(16,8))
  9. plt.plot(K, distortions, 'bx-')
  10. plt.xlabel('k')
  11. plt.ylabel('Distortion')
  12. plt.title('The Elbow Method showing the optimal k')
  13. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement