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')
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With