Skip to content

Instantly share code, notes, and snippets.

@makispl
Last active February 22, 2021 07:45
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/aa6135175e75257d20fd46f11277963a to your computer and use it in GitHub Desktop.
Save makispl/aa6135175e75257d20fd46f11277963a to your computer and use it in GitHub Desktop.
# Instantiate a KMeans model with 3 clusters, fit and predict cluster indices
kmeans = KMeans(n_clusters=3, init='k-means++', random_state=1)
kmeans.fit_predict(data)
df_no_nuls['cluster'] = kmeans.labels_
data['cluster'] = kmeans.labels_
df_no_nuls.cluster.value_counts()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment