Problem with Gmm Library from Sklear. Mixture?

Problem with Gmm Library from Sklear. Mixture?

I want to run this example about 1D Gaussian Mixture Example: 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.

2 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.

2

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. Here is the link to the OLD 0.18 module, which is the first instance i could find that shows a deprecation warning. if you want you can install an older version pip install -Iv scikit-learn==0.15, or if you want to use the newer version, adapt the parameters of your GaussianMixture to reflect their new names (e.g. in GaussianMixture, max_iter is the number of iterations, instead of n_iter).

2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Robert Thorne
Author

Robert Thorne

Robert Thorne covers electric vehicle innovations, autonomous driving systems, global mobility trends, and automotive engineering developments.