Skip to content

Instantly share code, notes, and snippets.

@karamanbk
Last active May 3, 2019 19:52
Show Gist options
  • Save karamanbk/3f0ef308a44ac3dccf768b3053f88e1e to your computer and use it in GitHub Desktop.
Save karamanbk/3f0ef308a44ac3dccf768b3053f88e1e to your computer and use it in GitHub Desktop.
from sklearn.cluster import KMeans
sse={}
tx_recency = tx_user[['Recency']]
for k in range(1, 10):
kmeans = KMeans(n_clusters=k, max_iter=1000).fit(tx_recency)
tx_recency["clusters"] = kmeans.labels_
sse[k] = kmeans.inertia_
plt.figure()
plt.plot(list(sse.keys()), list(sse.values()))
plt.xlabel("Number of cluster")
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment