Advertisement
blufzzz

silhouette_score_adj

Mar 9th, 2021
747
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.00 KB | None | 0 0
  1. # def silhouette_score_adj(distances, n_clusters, labels, nearest_other_cluster_mode='min'):
  2. #     for i in range(n_clusters):
  3. #         mask_i = labels==i
  4. #         n_i = mask_i.sum()
  5. #         assert n_i > 0
  6. #         # intra-cluster distance for each sample in i-cluster
  7. #         a = distances[mask_i][:,mask_i].reshape(n_i,n_i).mean(0)
  8.        
  9. #         other_cluster_numbers = list(range(n_clusters))
  10. #         other_cluster_numbers.remove(i)
  11. #         if nearest_other_cluster_mode == 'mean':
  12. #             bs = []
  13. #             for j in other_cluster_numbers:
  14. #                 mask_j = labels==j
  15. #                 n_j = mask_j.sum()
  16. #                 assert n_j > 0
  17. #                 b = distances[mask_i][:,mask_j].reshape(n_i, n_j).mean(1)
  18. #                 bs.append(b)
  19. #             bs = np.stack(bs, axis=1).min(1)
  20. #         else:
  21. #             bs = distances[mask_i][:,~mask_i].reshape(n_i, -1).min(1)
  22. #         s = (bs - a) / (np.stack([bs,a], axis=1).max(1))
  23. #         return s.mean()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement