Skip to content

Instantly share code, notes, and snippets.

@makispl
Last active August 31, 2021 09:43
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 makispl/66d51e1173a16d875526a72a1ca64c09 to your computer and use it in GitHub Desktop.
Save makispl/66d51e1173a16d875526a72a1ca64c09 to your computer and use it in GitHub Desktop.
# Switch to a new dataframe instance
# for the k-memans implementation
plays_km_df = plays_df.copy()
# Calculate the wcss
max_clusters = 11
wcss = list()
for k in range(1, max_clusters):
kmeans = KMeans(n_clusters=k, init='random', random_state=1)
kmeans.fit(pca_scores)
wcss.append(kmeans.inertia_)
# Locate the elbow
n_clusters = KneeLocator([i for i in range(1, max_clusters)], wcss, curve='convex', direction='decreasing').knee
print("Optimal # of clusters:", n_clusters)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment