Created
March 17, 2018 11:09
-
-
Save CharlesRajendran/45d0a48a07495244e3bce1651b39e3f1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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