Python sklearn.mixture.GMM规模不稳健?

时间:2012-10-31 15:55:25

标签: python machine-learning gaussian scikit-learn

我在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

原则上,我认为整体数据扩展并不重要,每次总日志可能性应该相似。但也许我忽视了一个实施问题?

2 个答案:

答案 0 :(得分:3)

我已经an answer via the scikit-learn mailing list:在我的代码示例中,对数似然应该确实随着比例而变化(因为我们正在评估点可能性,而不是积分) ,与log(scale)有关的因素。所以我认为我的代码示例实际上显示GMM给出了正确的结果。

答案 1 :(得分:2)

我认为GMM是依赖于规模的(例如k-means),因此建议按照the preprocessing chapter of the documentation中的说明标准化输入。