【发布时间】:2016-11-26 11:13:14
【问题描述】:
我正在尝试使用 scikit-learn 的 DPGMM 算法将混合法线模型拟合到一些数据中。 [0] 上宣传的优点之一是我不需要指定组件的数量;这很好,因为我不知道数据中的组件数量。文档指出我只需要指定一个上限。但是,看起来很不真实:
>>> data = numpy.random.normal(loc = 0.0, scale = 1.0, size = 1000)
>>> from sklearn.mixture import DPGMM
>>> d = DPGMM(n_components=5)
>>> d.fit(data.reshape(-1,1))
DPGMM(alpha=1.0, covariance_type='diag', init_params='wmc', min_covar=None,
n_components=5, n_iter=10, params='wmc', random_state=None, thresh=None,
tol=0.001, verbose=0)
>>> d.n_components
5
>>> d.means_
array([[-0.02283383],
[ 0.06259168],
[ 0.00390097],
[ 0.02934676],
[-0.05533165]])
如您所见,即使对于仅从一个正态分布中明显采样的数据,拟合也会报告五个分量(上限)。
我做错了吗?我是不是误会了什么?
非常感谢,
卢卡斯
[0]http://scikit-learn.org/stable/modules/mixture.html#dpgmm
【问题讨论】:
-
您为什么希望算法能够识别出一个组件就足够了?这是一个难题,该算法是一种没有强有力保证的启发式算法。来自您的链接:
only an upper bound of this number needs to be provided. Note however that the DPMM is not a formal model selection procedure, and thus provides no guarantee on the result.图片there 向您展示了可能发生的情况(取决于 alpha:选择 1 或 4 个组件),并且该算法有自己的调整参数 alpha 控制它 -
我意识到这是一个难题,算法只是一种启发式算法;但是,如果它总是导致最大数量的集群,那么启发式是无用的吗?我现在尝试使用从单个正态分布中提取的 10^{-10}、n_iter=1000 和 100000 个数据点的 alpha。我认为这是“最简单的问题”,它仍然会导致 10 个集群。换句话说:我无法构建算法确实没有完全失败的任何情况,所以我目前认为我做错了什么......
-
np.bincount(d.predict(data.reshape(-1, 1)))返回array([1000])。该算法正确地将所有训练点分配给单个混合分量。
标签: scipy statistics scikit-learn