Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AttributeError: 'GMM' object has no attribute 'covariances_' || AttributeError: 'module' object has no attribute 'GaussianMixture'

I have a snippet of code to fit the guassian model for my data. I have imported mixture from sklearn. However even I use mixture.GaussianMixture I get an error:AttributeError: 'module' object has no attribute 'GaussianMixture' and if I use the other way, it gives an error: AttributeError: 'GMM' object has no attribute 'covariances_'. I even tried importing covariance but doean't seem to work. Could anyone please let me know how to fix this error.

from sklearn import mixture   

# Fit a Gaussian mixture with EM using five components
gmm = mixture.GaussianMixture(n_components=5, covariance_type='full').fit(X) 
gmm = GMM(n_components=3, covariance_type='full')
like image 240
Joe Avatar asked Mar 20 '18 03:03

Joe


1 Answers

In the new versions from 0.18 onwards, GMM has been deprecated and GaussianMixture is used in place of that as can be seen in the documentation here.

Now for your first error, it seems that you have an older version of scikit-learn which dont have the GaussianMixture class yet. And for your second error, older GMM did not have the attribute covariances_. Use covars_ attribute instead. See the older documentation here:-

covars_ : array

Covariance parameters for each mixture component. 
The shape depends on covariance_type:

Then it wont throw any error.

Update the scikit-learn to the newest version to use the covariances_ attribute in the GaussianMixture class.

like image 135
Vivek Kumar Avatar answered Oct 15 '22 22:10

Vivek Kumar