Advertisement
gk231192

Module 10.2 Elbow Method

Jul 7th, 2025 (edited)
385
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.37 KB | None | 0 0
  1. # 2. Elbow Method
  2. sse = []
  3. k_range = range(1, 11)
  4. for k in k_range:
  5.     km = KMeans(n_clusters=k, random_state=42)
  6.     km.fit(X_scaled)
  7.     sse.append(km.inertia_)
  8.  
  9. plt.figure(figsize=(8, 4))
  10. plt.plot(k_range, sse, 'bo-')
  11. plt.xlabel('Number of clusters (k)')
  12. plt.ylabel('Sum of Squared Errors (SSE)')
  13. plt.title('Elbow Method for Optimal k')
  14. plt.grid(True)
  15. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement