(embeddings: np.ndarray, threshold: float, random_state: int = 0,cluster_size: int = 20)
| 228 | |
| 229 | |
| 230 | def GMM_cluster(embeddings: np.ndarray, threshold: float, random_state: int = 0,cluster_size: int = 20): |
| 231 | n_clusters = max(len(embeddings) // cluster_size,get_optimal_clusters(embeddings)) |
| 232 | gm = GaussianMixture( |
| 233 | n_components=n_clusters, |
| 234 | random_state=random_state, |
| 235 | n_init=5, |
| 236 | init_params='k-means++') |
| 237 | gm.fit(embeddings) |
| 238 | probs = gm.predict_proba(embeddings) # [num, cluster_num] |
| 239 | # labels = [np.where(prob > threshold)[0] for prob in probs] |
| 240 | labels = [[np.argmax(prob)] for prob in probs] |
| 241 | return labels, n_clusters |
| 242 | |
| 243 | |
| 244 | def perform_clustering( |
no test coverage detected