MCPcopy Create free account
hub / github.com/KnowledgeXLab/LeanRAG / GMM_cluster

Function GMM_cluster

_cluster_utils.py:230–241  ·  view source on GitHub ↗
(embeddings: np.ndarray, threshold: float, random_state: int = 0,cluster_size: int = 20)

Source from the content-addressed store, hash-verified

228
229
230def 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
244def perform_clustering(

Callers 1

perform_clusteringFunction · 0.85

Calls 1

get_optimal_clustersFunction · 0.85

Tested by

no test coverage detected