我在Python语言中使用sklearn.mixture.GMM,结果似乎依赖于数据缩放。在下面的代码示例中,我更改了整体缩放,但不更改尺寸的相对缩放。然而,在三种不同的缩放设置下,我得到了完全不同的结果:
from sklearn.mixture import GMM
from numpy import array, shape
from numpy.random import randn
from random import choice
# centroids will be normally-distributed around zero:
truelumps = randn(20, 5) * 10
# data randomly sampled from the centroids:
data = array([choice(truelumps) + randn(5) for _ in xrange(1000)])
for scaler in [0.01, 1, 100]:
scdata = data * scaler
thegmm = GMM(n_components=10)
thegmm.fit(scdata, n_iter=1000)
ll = thegmm.score(scdata)
print sum(ll)下面是我得到的输出:
GMM(cvtype='diag', n_components=10)
7094.87886779
GMM(cvtype='diag', n_components=10)
-14681.566456
GMM(cvtype='diag', n_components=10)
-37576.4496656原则上,我不认为总体数据缩放应该很重要,并且每次总的对数似然率应该是相似的。但也许有一个我忽略的实现问题?
发布于 2012-11-01 02:28:37
我已经有了an answer via the scikit-learn mailing list:在我的代码示例中,对数似然应该确实随着规模而变化(因为我们正在计算点可能性,而不是积分),通过与log(scale)相关的因子。因此,我认为我的代码示例实际上显示了GMM给出了正确的结果。
发布于 2012-11-01 00:27:50
我认为GMM是尺度相关的(例如k均值),因此建议按照the preprocessing chapter of the documentation中的解释对输入进行标准化。
https://stackoverflow.com/questions/13161923
复制相似问题