Last active
August 31, 2021 10:21
-
-
Save makispl/b0d6dd3e6cfefbb38660c998aaf5ea27 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
# Instantiate a KMeans model with 4 clusters, fit and predict cluster indices | |
kmeans_pca = KMeans(n_clusters=4, init='random', random_state=1) | |
kmeans_pca.fit_predict(pca_scores) | |
plays_km_df['km_cluster'] = kmeans_pca.labels_ | |
# concat plays_km_df with the pca components | |
plays_pca_km_df = pd.concat([plays_km_df.reset_index(drop=True), pd.DataFrame( | |
data=pca_scores, columns=['pca_1', 'pca_2', 'pca_3', 'pca_4'])], axis=1) | |
# visualize clusters | |
x_axis = plays_pca_km_df['pca_1'] | |
y_axis = plays_pca_km_df['pca_2'] | |
plt.figure(figsize=(10,8)) | |
sns.scatterplot(x_axis, y_axis, hue = plays_pca_km_df['km_cluster'], palette = ['g', 'r', 'c', 'b']) | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment