Last active
February 23, 2019 17:32
-
-
Save DFoly/0ca8089677ee3906cd10918b130e30df to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from sklearn.mixture import GaussianMixture | |
| sklearn_pca = PCA(n_components = 2) | |
| Y_sklearn = sklearn_pca.fit_transform(tf_idf_array) | |
| gmm = GaussianMixture(n_components=3, covariance_type='full').fit(Y_sklearn) | |
| prediction_gmm = gmm.predict(Y_sklearn) | |
| probs = gmm.predict_proba(Y_sklearn) | |
| centers = np.zeros((3,2)) | |
| for i in range(3): | |
| density = mvn(cov=gmm.covariances_[i], mean=gmm.means_[i]).logpdf(Y_sklearn) | |
| centers[i, :] = Y_sklearn[np.argmax(density)] | |
| plt.figure(figsize = (10,8)) | |
| plt.scatter(Y_sklearn[:, 0], Y_sklearn[:, 1],c=prediction_gmm ,s=50, cmap='viridis') | |
| plt.scatter(centers[:, 0], centers[:, 1],c='black', s=300, alpha=0.6); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment