微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

获取 Scikit 预测的每个高斯曲线的参数学习高斯混合模型?

如何解决获取 Scikit 预测的每个高斯曲线的参数学习高斯混合模型?

我正在尝试将多条高斯曲线拟合到我的实验数据中。高斯混合模型是使用 sci-kit learn Mixture 模型获得的。 GM 拟合我的实验数据如下图所示。

GMM fit over experimental data.

如您所见,多条高斯曲线拟合了我的数据。但是,我只想保留最高峰值的两条曲线,并希望获得这两条高斯曲线的参数,以便我可以独立绘制这两条特定的高斯曲线(请注意,仅凭均值和协方差不足以重现它们,我还需要知道缩放参数)。有没有办法这样做?我附上了下面的代码

import numpy as np
import matplotlib.pyplot as plt
import matplotlib
import matplotlib.ticker as ticker
from sklearn.mixture import GaussianMixture
import random as random
## Generating random data resembling experimental data
C1 = np.zeros(2000)
for c in range(2000):
    if c<=400:
        C1[c] = random.gauss(0.7,0.2)
    elif c<=600:
        C1[c] = random.gauss(0.9,0.25)
    elif c<= 800:
        C1[c] = random.gauss(2.5,0.2)
    elif c<= 1200:
        C1[c] = random.gauss(1.5,0.5)
    elif c<=1600:
        C1[c] = random.gauss(5,3.5)
    elif c<2000:
        C1[c] = random.gauss(10,5)
C1[C1<0] = 0
C1 = np.sort(C1)
#### Plotting a normalised histogram
fig,ax = plt.subplots()
fig.set_figheight(10)
fig.set_figwidth(10)
n,bins,patches = ax.hist(C1,bins = 250,align = 'mid',density = True,color = 'grey' )

""" Using machine Learning i.e Gaussian mixture models """
### Using GMM to predict different Gaussain Curves
X = np.array(C1)
gmm = GaussianMixture(n_components=6,random_state=0).fit(X.reshape(-1,1))
labels = gmm.predict(X.reshape(-1,1))
gmm_y = np.exp(gmm.score_samples(X.reshape(-1,1)))
ax.plot(X.reshape(-1,1),gmm_y,color="crimson",lw=2,label="GMM")
ax.tick_params(labelsize=26)

我找到了问题 here 的答案。谢谢

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。