Skip to content

Instantly share code, notes, and snippets.

@CharlesRajendran
Created March 17, 2018 11:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CharlesRajendran/45d0a48a07495244e3bce1651b39e3f1 to your computer and use it in GitHub Desktop.
Save CharlesRajendran/45d0a48a07495244e3bce1651b39e3f1 to your computer and use it in GitHub Desktop.
X = data.iloc[:, 1:3]
# use elbow mwthod to find optimal number of clusters
from sklearn.cluster import KMeans
# with in cluster sum of squares
wcss = []
for i in range(1, 11):
kmeans = KMeans(n_clusters =i, init="k-means++", max_iter=300, n_init=10)
kmeans.fit(X)
wcss.append(kmeans.inertia_)
plt.plot(range(1, 11), wcss);
plt.title("Elbow Method")
plt.xlabel("Number 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