나는 초기 매개 변수에 대해 이미 꽤 잘 알고있는 가우시안 (gaussians)을 맞추려고한다. (이 경우 배포본을 생성하기 때문에 항상 이것들을 적용 할 수 있어야한다.) 그러나, 나는 평균을 강요하는 방법을 알아낼 수 없다. 두 가우시안 모두 0. 가능한가? m.means_ = ...
가 작동하지 않습니다.Sklearn Gaussian 혼합 잠금 매개 변수?
from sklearn import mixture
import numpy as np
import math
import matplotlib.pyplot as plt
from scipy import stats
a = np.random.normal(0, 0.2, 500)
b = np.random.normal(0, 2, 800)
obs = np.concatenate([a,b]).reshape(-1,1)
plt.hist(obs, bins = 100, normed = True, color = "lightgrey")
min_range = -8
max_range = 8
n_gaussians = 2
m = mixture.GaussianMixture(n_components = n_gaussians)
m.fit(obs)
# # Get the gaussian parameters
weights = m.weights_
means = m.means_
covars = m.covariances_
# Plot all gaussians
n_gaussians = 2
gaussian_sum = []
for i in range(n_gaussians):
mean = means[i]
sigma = math.sqrt(covars[i])
plotpoints = np.linspace(min_range,max_range, 1000)
gaussian_points = weights[i] * stats.norm.pdf(plotpoints, mean, sigma)
gaussian_points = np.array(gaussian_points)
gaussian_sum.append(gaussian_points)
plt.plot(plotpoints,
weights[i] * stats.norm.pdf(plotpoints, mean, sigma))
sum_gaussian = np.sum(gaussian_sum, axis=0)
plt.plot(plotpoints, sum_gaussian, color = "black", linestyle = "--")
plt.xlim(min_range, max_range)
plt.show()
초기 추측 대신 특정 범위의 매개 변수를 강제 적용하거나 제한 할 수 있습니까? –
코드를 변경하지 않아도됩니다. 이것이 내 의견으로는 전체 EM 접근법을 무효로! (그러나 나는 나 자신을 전문가라고 생각하지 않을 것이다). – sascha