Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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