Skip to content

Instantly share code, notes, and snippets.

@amankharwal
Created December 4, 2020 06:20
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save amankharwal/096dc79c894b71d64650f0670a96692c to your computer and use it in GitHub Desktop.
from sklearn.cluster import KMeans
wcss = []
for i in range(1, 11):
km = KMeans(n_clusters = i,
init = 'k-means++',
max_iter = 300,
n_init = 10,
random_state = 0,
algorithm = 'full',
tol = 0.001)
km.fit(x)
labels = km.labels_
wcss.append(km.inertia_)
plt.rcParams['figure.figsize'] = (13, 7)
plt.plot(range(1, 11), wcss)
plt.grid()
plt.tight_layout()
plt.title('The Elbow Method', fontsize = 20)
plt.xlabel('No. of Clusters')
plt.ylabel('wcss')
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment