daily pastebin goal
58%
SHARE
TWEET

Untitled

a guest Mar 26th, 2019 80 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from sklearn.metrics import pairwise_distances_argmin_min
  2. import numpy as np
  3. from sklearn.cluster import KMeans
  4. kmeans = KMeans(n_clusters=n_clusters)
  5. kmeans = kmeans.fit(encoded)
  6.  
  7. n_clusters = int(np.ceil(len(encoded)**0.6))
  8. print(n_clusters)
  9.  
  10. avg = []
  11. for j in range(n_clusters):
  12.     idx = np.where(kmeans.labels_ == j)[0]
  13.     avg.append(np.mean(idx))
  14. closest, _ = pairwise_distances_argmin_min(kmeans.cluster_centers_, encoded)
  15. ordering = sorted(range(n_clusters), key=lambda k: avg[k])
  16. summary = ' '.join([sentences[closest[idx]] for idx in ordering])
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top