Skip to content

Instantly share code, notes, and snippets.

@kushalchauhan98
Created August 2, 2018 14:11
Show Gist options
  • Save kushalchauhan98/443c48ff4219a920be7c4035e5375b61 to your computer and use it in GitHub Desktop.
Save kushalchauhan98/443c48ff4219a920be7c4035e5375b61 to your computer and use it in GitHub Desktop.
Summarize
from sklearn.metrics import pairwise_distances_argmin_min
avg = []
for j in range(n_clusters):
idx = np.where(kmeans.labels_ == j)[0]
avg.append(np.mean(idx))
closest, _ = pairwise_distances_argmin_min(kmeans.cluster_centers_, encoded)
ordering = sorted(range(n_clusters), key=lambda k: avg[k])
summary = ' '.join([email[closest[idx]] for idx in ordering])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment