1D модель гауссовой смеси - PullRequest
0 голосов
/ 15 октября 2019

Можно ли построить всю итерацию обучающих данных, используя skylearn GMM?

Другое дело, мой код размещен ниже, и, как вы можете видеть, когда он будет построен, он вернет "маленьких" гауссианцев. по сравнению с PDF кто-нибудь знает почему?

import math
import matplotlib.pyplot as plt
from sklearn import cluster, datasets, mixture
import numpy as np
from scipy.stats import multivariate_normal
from scipy import stats

n_samples = 1000
mu1, sigma1 = -4, 1.2 # mean and variance
mu2, sigma2 = 4, 1.8 # mean and variance
mu3, sigma3 = 0, 1.6 # mean and variance

x1 = np.random.normal(mu1, np.sqrt(sigma1), n_samples)
x2 = np.random.normal(mu2, np.sqrt(sigma2), n_samples)
x3 = np.random.normal(mu3, np.sqrt(sigma3), n_samples)

X = np.array(list(x1) + list(x2) + list(x3))
np.random.shuffle(X)
#print("Dataset:")
#print(X)

a = np.zeros(np.size(X))
plt.plot(X,a,'|b')

#plot pdf
x1 = np.sort(x1)
y1 = multivariate_normal.pdf (x1,mu1,np.sqrt(sigma1))
plt.plot(x1,y1, color = 'gray')

x2 = np.sort(x2)
y2 = multivariate_normal.pdf (x2,mu2,np.sqrt(sigma2))
plt.plot(x2,y2, color = 'gray')

x3 = np.sort(x3)
y3 = multivariate_normal.pdf (x3,mu3,np.sqrt(sigma3))
plt.plot(x3,y3, color = 'gray')

#full training
X = np.sort(X)
X = X.reshape(-1, 1)
g = mixture.GaussianMixture(n_components=3)
g.fit(X)

weights = g.weights_
means = g.means_
covars = g.covariances_

mean = means[0]
sigma = np.sqrt(covars[0])
plt.plot(X,weights[0]*multivariate_normal.pdf(X,mean,sigma), c='red')

mean = means[1]
sigma = np.sqrt(covars[1])
plt.plot(X,weights[1]*multivariate_normal.pdf(X,mean,sigma), c='blue')

mean = means[2]
sigma = np.sqrt(covars[2])
plt.plot(X,weights[2]*multivariate_normal.pdf(X,mean,sigma), c='green')

plt.show()

Спасибо

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...