gpt4 book ai didi

python - 属性错误 : 'GMM' object has no attribute 'covariances_' || AttributeError: 'module' object has no attribute 'GaussianMixture'

转载 作者:太空宇宙 更新时间:2023-11-03 13:08:48 28 4
gpt4 key购买 nike

我有一段代码可以为我的数据拟合高斯模型。我从 sklearn 导入了混合物。但是,即使我使用 mixture.GaussianMixture,我也会收到错误消息:AttributeError: 'module' object has no attribute 'GaussianMixture' 如果我使用另一种方式,它会给出一个错误:AttributeError: 'GMM' object has no attribute '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 代替它,如 documentation here. 中所示

现在对于您的第一个错误,您似乎有一个旧版本的 scikit-learn,它还没有 GaussianMixture 类。对于第二个错误,旧版 GMM 没有 covariances_ 属性。请改用 covars_ 属性。见老documentation here :-

covars_ : array

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

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

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

关于python - 属性错误 : 'GMM' object has no attribute 'covariances_' || AttributeError: 'module' object has no attribute 'GaussianMixture' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49375927/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com