AttributeError: 'GMM'对象没有属性'covariances_' || AttributeError:'module'对象没有属性'GaussianMixture'

9

我有一段代码,用于拟合我的数据的高斯模型。我已经从sklearn中导入了混合物(mixture)。但是,即使我使用mixture.GaussianMixture,我仍然会收到错误信息:AttributeError: 'module' object has no attribute 'GaussianMixture',如果我使用另一种方式,则会出现错误:AttributeError: 'GMM' object has no attribute 'covariances_'。我甚至尝试了导入covariance,但似乎不起作用。请问有谁可以告诉我如何解决这个错误。

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')
1个回答

16
自0.18版本以后,GMM已被弃用,取而代之的是GaussianMixture,如此文档所示。
现在看看你的第一个错误,似乎你的scikit-learn版本较旧,还没有GaussianMixture类。至于第二个错误,早期的GMM没有属性。请使用covars_属性。请参见旧版文档:-

covars_ : array

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

那么它就不会抛出任何错误。

将scikit-learn更新到最新版本,以使用GaussianMixture类中的covariances_属性。


将scikit learn的版本更新到0.18版成功了 :) 谢谢 - Joe

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接