这是
mixture of gaussians,并且可以使用
expectation maximization方法估算(基本上,它在估计它们如何混合在一起的同时找到分布的中心和均值).
这在PyMix包中实现.下面我生成一个法线混合的例子,并使用PyMix将混合模型拟合到它们中,包括找出你感兴趣的东西,即子群体的大小:
# requires numpy and PyMix (matplotlib is just for making a histogram)
import random
import numpy as np
from matplotlib import pyplot as plt
import mixture
random.seed(010713) # to make it reproducible
# create a mixture of normals:
# 1000 from N(0, 1)
# 2000 from N(6, 2)
mix = np.concatenate([np.random.normal(0, 1, [1000]),
np.random.normal(6, 2, [2000])])
# histogram:
plt.hist(mix, bins=20)
plt.savefig("mixture.pdf")
以上所有代码都生成并绘制混合物.它看起来像这样:
现在实际使用PyMix来确定百分比是多少:
data = mixture.DataSet()
data.fromArray(mix)
# start them off with something arbitrary (probabl