python & scikit: How to get parameters of fitted model from Gaussian mixture model fit?


year 1991

After fitting gaussian mixture model(XY dataset), how can I get the parameters of each distribution? For example mean, std, and weights and angleeach 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 draw an ellipse, you need to know mean,std,angle,weight. But the code is really complicated and I wonder if there is any easier way?

Update: I found the property in http://scikit-learn.org/stable/modules/generated/sklearn.mixture.GMM.html#sklearn.mixture.GMM.fit and now I'm working on it.

Camilleri

As you're reading scikit's doc on GMM , once you've trained the model (call it clf), you can access its paremeters using clf.means_, clf.covars_and clf.weights_.

I would add that you can use the values ​​to check if your model is trained/convergedclf.converged_

Related


Get PDF from Gaussian Mixture Model in sklearn

learner I have fitted a Gaussian Mixture Model (GMM) to the data series I have. Using GMM, I am trying to get the probability of another vector, element-wise. Matlab achieves this with the following lines of code. a = reshape(0:1:15, 14, 1); gm = fitgmdist(a,

Number of parameters in a Gaussian mixture model

golden_truth I have D-dimensional data with K components. How many parameters do I need if I use a model with a full covariance matrix? and if I use the diagonal covariance matrix how many? golden_truth xyLe_ 's answer in CrossValidated https://stats.stackexch

How to get number of features from fitted scikit-learn model?

Wavlin I am trying to extract the number of features from the model after fitting the model to the data. I browsed the catalog of models and found ways to get only a specific model number (e.g. looking at the dimensionality of the SVM support vector), but I di

How to get number of features from fitted scikit-learn model?

Wavlin I am trying to extract the number of features from the model after fitting the model to the data. I browsed the catalog of models and found ways to get only a specific model number (e.g. looking at the dimensionality of the SVM support vector), but I di

How to get number of features from fitted scikit-learn model?

Wavlin I am trying to extract the number of features from the model after fitting the model to the data. I browsed the catalog of models and found ways to get only a specific model number (e.g. looking at the dimensionality of the SVM support vector), but I di

Equivalent of Matlab "fit" of Gaussian mixture model in R?

Dentist_Not edible I have some time series data that looks like this: x <- c(0.5833, 0.95041, 1.722, 3.1928, 3.941, 5.1202, 6.2125, 5.8828, 4.3406, 5.1353, 3.8468, 4.233, 5.8468, 6.1872, 6.1245, 7.6262, 8.6887, 7.7549, 6.9805, 4.3217, 3.0347, 2.4026, 1.9317,

Sampling data points from Gaussian mixture model python

Yufeng I am really new to python and GMM. I recently learned GMM and tried to implement the code from here I have some problems running the gmm.sample() method: gmm16 = GaussianMixture(n_components=16, covariance_type='full', random_state=0) Xnew = gmm16.s

Sampling data points from Gaussian mixture model python

Yufeng I am really new to python and GMM. I recently learned GMM and tried to implement the code from here I have some problems running the gmm.sample() method: gmm16 = GaussianMixture(n_components=16, covariance_type='full', random_state=0) Xnew = gmm16.s

How to evaluate samples in a weighted Gaussian mixture model?

kind Lite: If I have a MoG model with n components, each component has its own weight w^n. I have a sample. I wish to calculate the probability of drawing samples from the MoG. I can easily evaluate individual Gaussians, but I don't know how to consider their

Gaussian Mixture Model for Image Histogram

Dotted glass I am trying to do automatic image segmentation of different regions of a 2D MR image based on pixel intensity values. The first step is to implement a Gaussian mixture model on the histogram of the image. I need to plot the resulting Gaussian obta

Gaussian Mixture Model for Image Histogram

Dotted glass I am trying to do automatic image segmentation of different regions of a 2D MR image based on pixel intensity values. The first step is to implement a Gaussian mixture model on the histogram of the image. I need to plot the resulting Gaussian obta

Gaussian Mixture Model Cross Validation

Newkid I want to perform cross validation on my Gaussian mixture model. Currently, my cross_validationapproach using sklearn is as follows. clf = GaussianMixture(n_components=len(np.unique(y)), covariance_type='full') cv_ortho = cross_validate(clf, parameters_

Gaussian Mixture Model for Image Histogram

Dotted glass I am trying to do automatic image segmentation of different regions of a 2D MR image based on pixel intensity values. The first step is to implement a Gaussian mixture model on the histogram of the image. I need to plot the resulting Gaussian obta

Gaussian Mixture Model Cross Validation

Newkid I want to perform cross validation on my Gaussian mixture model. Currently, my cross_validationapproach using sklearn is as follows. clf = GaussianMixture(n_components=len(np.unique(y)), covariance_type='full') cv_ortho = cross_validate(clf, parameters_

Gaussian Mixture Model (GMM) is not suitable

Book I've been using Scikit-learn's GMM function. First, I created a distribution along the line x=y. from sklearn import mixture import numpy as np import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D line_model = mixture.GMM(n_components

Gaussian Mixture Model (GMM) is not suitable

BenB I've been using Scikit-learn's GMM function. First, I created a distribution along the line x=y. from sklearn import mixture import numpy as np import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D line_model = mixture.GMM(n_components

Gaussian Mixture Model Cross Validation

Newkid I want to perform cross validation on my Gaussian mixture model. Currently, my cross_validationapproach using sklearn is as follows. clf = GaussianMixture(n_components=len(np.unique(y)), covariance_type='full') cv_ortho = cross_validate(clf, parameters_

Gaussian Mixture Model for Image Histogram

Dotted glass I am trying to do automatic image segmentation of different regions of a 2D MR image based on pixel intensity values. The first step is to implement a Gaussian mixture model on the histogram of the image. I need to plot the resulting Gaussian obta

Gaussian Mixture Model for Image Histogram

Dotted glass I am trying to do automatic image segmentation of different regions of a 2D MR image based on pixel intensity values. The first step is to implement a Gaussian mixture model on the histogram of the image. I need to plot the resulting Gaussian obta

Gaussian Mixture Model Cross Validation

Newkid I want to perform cross validation on my Gaussian mixture model. Currently, my cross_validationapproach using sklearn is as follows. clf = GaussianMixture(n_components=len(np.unique(y)), covariance_type='full') cv_ortho = cross_validate(clf, parameters_