高斯混合模型以找到概率分布?

时间:2019-06-11 11:20:25

标签: python scikit-learn probability-density

我正在尝试将高斯混合模型拟合到我的数据并估算参数。我能够拟合模型并找到参数,但拟合曲线未达到数据分布的峰值。 以下是我的代码和数据的直方图。 如图中所示,曲线的峰值未达到峰值数据,要实现该目标,我需要对哪个参数或代码进行哪些更改?

from sklearn.mixture import GaussianMixture
gmm = GaussianMixture(n_components = 3,max_iter=150)
gmm.fit(np.expand_dims(data, 1)) # Parameters: array-like, shape `(`n_samples, n_features), 1 dimension dataset so 1 feature
Gaussian_nr = 1
for mu, sd, p in zip(gmm.means_.flatten(), np.sqrt(gmm.covariances_.flatten()), gmm.weights_):
    print('Gaussian {:}: μ = {:.2}, σ = {:.2}, weight = {:.2}'.format(Gaussian_nr, mu, sd, p))
    g_s = stats.norm(mu, sd).pdf(x) * p
    plt.plot(x, g_s, label='gaussian sklearn');
    Gaussian_nr += 1
sns.distplot(data, bins=200, kde=False, norm_hist=True)
gmm_sum = np.exp([gmm.score_samples(e.reshape(-1, 1)) for e in x]) #gmm gives log probability, hence the exp() function
plt.plot(x, gmm_sum, label='gaussian mixture');
plt.legend();

enter image description here

0 个答案:

没有答案