簡體   English   中英

AttributeError:'GMM'對象沒有屬性'covariances_'|| AttributeError:'module'對象沒有屬性'GaussianMixture'

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

我有一段代碼可以適合我的數據的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')

在從0.18開始的新版本中,GMM已被棄用,並使用GaussianMixture代替它,如此處的文檔中所示。

現在為你的第一個錯誤,似乎你有一個舊版本的scikit-learn還沒有GaussianMixture類。 而對於您的第二個錯誤,舊的GMM沒有屬性covariances_ _。 請改用covars_屬性。 請參閱此處的舊文檔 : -

covars_:數組

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

然后它不會拋出任何錯誤。

更新scikit-learn到最新版本以使用GaussianMixture類中的covariances_屬性。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM