Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # 2. Elbow Method
- sse = []
- k_range = range(1, 11)
- for k in k_range:
- km = KMeans(n_clusters=k, random_state=42)
- km.fit(X_scaled)
- sse.append(km.inertia_)
- plt.figure(figsize=(8, 4))
- plt.plot(k_range, sse, 'bo-')
- plt.xlabel('Number of clusters (k)')
- plt.ylabel('Sum of Squared Errors (SSE)')
- plt.title('Elbow Method for Optimal k')
- plt.grid(True)
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement