Skip to content

Instantly share code, notes, and snippets.

@DFoly
Created February 23, 2019 18:09
Show Gist options
  • Select an option

  • Save DFoly/75db5fa932b27814427a7d4b7b2ef0d2 to your computer and use it in GitHub Desktop.

Select an option

Save DFoly/75db5fa932b27814427a7d4b7b2ef0d2 to your computer and use it in GitHub Desktop.
model = GMM(3, n_runs = 30)
fitted_values = model.fit(Y_sklearn)
predicted_values = model.predict(Y_sklearn)
# # compute centers as point of highest density of distribution
centers = np.zeros((3,2))
for i in range(model.C):
density = mvn(cov=model.sigma[i], mean=model.mu[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=predicted_values ,s=50, cmap='viridis', zorder=1)
plt.scatter(centers[:, 0], centers[:, 1],c='black', s=300, alpha=0.5, zorder=2);
w_factor = 0.2 / model.pi.max()
for pos, covar, w in zip(model.mu, model.sigma, model.pi):
draw_ellipse(pos, covar, alpha = w)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment