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

Joe*_*Joe 4 python scikit-learn

我有一段代码可以适合我的数据的guassian模型.我从sklearn进口了混合物.然而,即使我使用mixture.GaussianMixture我得到一个错误:AttributeError:'module'对象没有属性'GaussianMixture',如果我使用另一种方式,它会给出一个错误:AttributeError:'GMM'对象没有属性'covariances_'.我甚至尝试导入协方差,但似乎没有用.谁能告诉我如何解决这个错误.

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')
Run Code Online (Sandbox Code Playgroud)

Viv*_*mar 8

在从0.18开始的新版本中,GMM已被弃用,并使用GaussianMixture代替它,如此处的文档中所示.

现在为你的第一个错误,似乎你有一个旧版本的scikit-learn还没有GaussianMixture类.而对于您的第二个错误,旧的GMM没有该属性covariances_.请改用covars_属性.请参阅此处的旧文档: -

covars_:数组

Covariance parameters for each mixture component. 
The shape depends on covariance_type:
Run Code Online (Sandbox Code Playgroud)

然后它不会抛出任何错误.

更新scikit-learn到最新版本以使用covariances_GaussianMixture类中的属性.