Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problem with GMM library from sklear.mixture?

Tags:

python

I want to run this example about 1D Gaussian Mixture Example: http://www.astroml.org/book_figures/chapter4/fig_GMM_1D.html But I have this error all the time:

    from sklearn.mixture import GMM
ImportError: cannot import name 'GMM'

I tried to replace it by from sklearn.mixture import GaussianMixture but the code does not work, they do not have the same functionalities.

Thank you in advance.

like image 969
dina Avatar asked Apr 22 '19 18:04

dina


People also ask

How do you initialize a Gaussian mixture?

The simplest way to initiate the GMM is to pick numClusters data points at random as mode means, initialize the individual covariances as the covariance of the data, and assign equa prior probabilities to the modes. This is the default initialization method used by vl_gmm .

What is Gaussian mixture model Python?

A Gaussian mixture model (GMM) attempts to find a mixture of multi-dimensional Gaussian probability distributions that best model any input dataset. In the simplest case, GMMs can be used for finding clusters in the same manner as k-means: from sklearn.mixture import GMM gmm = GMM(n_components=4). fit(X) labels = gmm.

How does GMM work?

At its simplest, GMM is also a type of clustering algorithm. As its name implies, each cluster is modelled according to a different Gaussian distribution. This flexible and probabilistic approach to modelling the data means that rather than having hard assignments into clusters like k-means, we have soft assignments.

What is the advantage of using the GMM class?

This class allows for easy evaluation of, sampling from, and maximum-likelihood estimation of the parameters of a GMM distribution. Initializes parameters such that every mixture component has zero mean and identity covariance.

Is there a gaussianmixture sample function for Gaussian mixture?

GaussianMixture is designed to fit a Gaussian Mixture and this is for that reason that it doesn't check that np.sum (weights) = 1, ... This issue is linked to #7701 : I think what people want is a sample function outside GaussianMixture.

What happened to the scikit-learn module?

The newer versions of scikit-learn don't have that module. From looking at the versions it was deprecated in v 0.18 and removed in v 0.20.


1 Answers

sklearn Gaussian Mixture implementation

Old (outdated, not supported in newer sklearn versions):

from sklearn.mixture import GMM     
model = GMM(n_components=3,covariance_type='full')

New and supported

from sklearn import mixture
model = mixture.GaussianMixture(n_components=3, covariance_type='full')

n_components default value is 1, choose what you want. That's number of mixture components.

like image 67
Hrvoje Avatar answered Sep 19 '22 07:09

Hrvoje