Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- distortions = []
- K = range(1,10)
- for k in K:
- kmeanModel = KMeans(n_clusters=k)
- kmeanModel.fit(X)
- distortions.append(kmeanModel.inertia_)
- plt.figure(figsize=(16,8))
- plt.plot(K, distortions, 'bx-')
- plt.xlabel('k')
- plt.ylabel('Distortion')
- plt.title('The Elbow Method showing the optimal k')
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement