Skip to content

Latest commit

 

History

History
17 lines (15 loc) · 409 Bytes

4_Clustering.md

File metadata and controls

17 lines (15 loc) · 409 Bytes

- K-means Clustering

Elbow method to find the optimal nymber of clusters

from sklearn.cluster import KMeans
wcss = []
for i in range(1, 11):
    kmeans = KMeans(n_clusters = i, init = 'k-means++', random_state = 42)
    kmeans.fit(X)
    wcss.append(kmeans.inertia_)
plt.plot(range(1, 11), wcss)
plt.title('The Elbow Method')
plt.xlabel('Number of clusters')
plt.ylabel('WCSS')
plt.show()