问题描述
我正在尝试将多条高斯曲线拟合到我的实验数据中。高斯混合模型是使用 sci-kit learn Mixture 模型获得的。 GM 拟合我的实验数据如下图所示。
如您所见,多条高斯曲线拟合了我的数据。但是,我只想保留最高峰值的两条曲线,并希望获得这两条高斯曲线的参数,以便我可以独立绘制这两条特定的高斯曲线(请注意,仅凭均值和协方差不足以重现它们,我还需要知道缩放参数)。有没有办法这样做?我附上了下面的代码。
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 (将#修改为@)