获取 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 (将#修改为@)

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...