Last active
August 31, 2021 09:43
-
-
Save makispl/66d51e1173a16d875526a72a1ca64c09 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
# 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