ZK Zhao
ZK Zhao

Reputation: 21513

python & scikit: How to get the parameter of fitted models from Gaussian mixture models fitting?

After fitting the gaussian mixture model(X-Y dataset), how can I get the parameter of each distribution? e.g. mean, std, and weights and angle of each distribution?

I think I can find the code here:

def make_ellipses(gmm, ax):
    for n, color in enumerate('rgb'):
        v, w = np.linalg.eigh(gmm._get_covars()[n][:2, :2])
        u = w[0] / np.linalg.norm(w[0])
        angle = np.arctan2(u[1], u[0])
        angle = 180 * angle / np.pi  # convert to degrees
        v *= 9
        ell = mpl.patches.Ellipse(gmm.means_[n, :2], v[0], v[1],
                                  180 + angle, color=color)
        ell.set_clip_box(ax.bbox)
        ell.set_alpha(0.5)
        ax.add_artist(ell)

After all, to plot the ellipse, you need to know the mean,std,angle,weight. But the code is really complex and I am wondering if there is any simpler method for it?

UPDATE: I find the attributes in http://scikit-learn.org/stable/modules/generated/sklearn.mixture.GMM.html#sklearn.mixture.GMM.fit, now I'm working on it.

Upvotes: 2

Views: 4052

Answers (1)

P. Camilleri
P. Camilleri

Reputation: 13218

As you can read in scikit's doc for GMM, once you have trained your model (call it clf), you can access its paremeters using clf.means_, clf.covars_ and clf.weights_.

I'll add that you can check whether your model has been trained/has converged using the value of clf.converged_

Upvotes: 4

Related Questions