Skip to content

Instantly share code, notes, and snippets.

@makispl
Last active Aug 31, 2021
Embed
What would you like to do?
# 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