【发布时间】:2020-03-04 04:02:44
【问题描述】:
我有兴趣将 2 分量高斯混合模型拟合到下面显示的数据。 但是,由于我在这里绘制的是标准化为 0-1 之间的对数转换计数,这是我的数据的最大值will ever take is 0. 当我尝试使用 sklearn.mixture.GaussianMixture(下面的代码)进行简单拟合时,我得到了结果拟合,这显然不是我想要的。
from sklearn.mixture import GaussianMixture
import numpy as np
# start with some count data in (0,1]
logged_counts = np.log(counts)
model = GaussianMixture(2).fit(logged_counts.reshape(-1,1))
# plot resulting fit
x_range = np.linspace(np.min(logged_counts), 0, 1000)
pdf = np.exp(model.score_samples(x_range.reshape(-1, 1)))
responsibilities = model.predict_proba(x_range.reshape(-1, 1))
pdf_individual = responsibilities * pdf[:, np.newaxis]
plt.hist(logged_counts, bins='auto', density=True, histtype='stepfilled', alpha=0.5)
plt.plot(x_range, pdf, '-k', label='Mixture')
plt.plot(x_range, pdf_individual, '--k', label='Components')
plt.legend()
plt.show()
如果我可以将顶部分量的均值固定为 0,并且只优化另一个均值、两个方差和混合分数,我会很高兴。 (此外,我希望能够为右侧的组件使用半正常值。)是否有一种简单的方法可以使用 python/sklearn 中的内置函数来做到这一点,或者我必须自己构建该模型使用某种概率编程语言?
【问题讨论】:
-
请分享您迄今为止为制作情节所做的尝试;看看如何创建minimal reproducible example。
-
@desertnaut 谢谢你的建议,刚刚做了!
标签: python scikit-learn gmm mixture