Untitled
from sklearn.mixture import GaussianMixture import numpy as np lowest_bic = np.infty best_gmm = None n_components_range = range(1, 20) # try different numbers for n in n_components_range: gmm = GaussianMixture(n_components=n, covariance_type='full', random_state=42) gmm.fit(embeddings) bic = gmm.bic(embeddings) if bic < lowest_bic: lowest_bic = bic best_gmm = gmm cluster_labels = best_gmm.predict(embeddings)
Leave a Comment