【问题标题】:sci-kit learn agglomerative clustering errorscikit学习凝聚聚类错误
【发布时间】:2016-11-11 13:07:47
【问题描述】:

我正在尝试使用 sklearn 进行凝聚聚类。在拟合步骤中,我收到此错误。错误不会一直出现,如果我更改数据点的数量,那么我可能不会得到错误和凝聚聚类。我不太确定如何调试它。我已经使用fillnan 确保我的数据数组中没有NaN 值。关于为什么会发生这种情况的任何想法都会有所帮助。

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-38-8acbe956f76e> in <module>()
     13     agg = AgglomerativeClustering(n_clusters=k,affinity="euclidean",linkage="ward")
     14     init = time.time()
---> 15     agg.fit(data)
     16     atime = time.time()
     17     labels = agg.labels_

C:\Python27\lib\site-packages\sklearn\cluster\hierarchical.pyc in fit(self, X, y)
    754                                        n_components=self.n_components,
    755                                        n_clusters=n_clusters,
--> 756                                        **kwargs)
    757         # Cut the tree
    758         if compute_full_tree:

C:\Python27\lib\site-packages\sklearn\externals\joblib\memory.pyc in __call__(self, *args, **kwargs)
    279 
    280     def __call__(self, *args, **kwargs):
--> 281         return self.func(*args, **kwargs)
    282 
    283     def call_and_shelve(self, *args, **kwargs):

C:\Python27\lib\site-packages\sklearn\cluster\hierarchical.pyc in ward_tree(X, connectivity, n_components, n_clusters, return_distance)
    189                           'for the specified number of clusters',
    190                           stacklevel=2)
--> 191         out = hierarchy.ward(X)
    192         children_ = out[:, :2].astype(np.intp)
    193 

C:\Python27\lib\site-packages\scipy\cluster\hierarchy.pyc in ward(y)
    463 
    464     """
--> 465     return linkage(y, method='ward', metric='euclidean')
    466 
    467 

C:\Python27\lib\site-packages\scipy\cluster\hierarchy.pyc in linkage(y, method, metric)
    662             Z = np.zeros((n - 1, 4))
    663             _hierarchy.linkage(dm, Z, n,
--> 664                                int(_cpy_euclid_methods[method]))
    665     return Z
    666 

scipy\cluster\_hierarchy.pyx in scipy.cluster._hierarchy.linkage (scipy\cluster\_hierarchy.c:8759)()

C:\Python27\lib\site-packages\scipy\cluster\_hierarchy.pyd in View.MemoryView.memoryview_copy_contents (scipy\cluster\_hierarchy.c:22026)()

C:\Python27\lib\site-packages\scipy\cluster\_hierarchy.pyd in View.MemoryView._err_extents (scipy\cluster\_hierarchy.c:21598)()

ValueError: got differing extents in dimension 0 (got 704882705 and 4999850001)

【问题讨论】:

  • 你有一个最小的例子供我们使用吗?

标签: python scikit-learn hierarchical-clustering


【解决方案1】:

这是一个溢出问题,请注意 4999850001 - 2**32 = 704882705(输出的最后一行)。某些东西太大而无法放入 32 位整数。您应该尝试使用更少的数据点。

【讨论】:

  • 你可能是对的,因为当我的记录少于 1e3 时它似乎工作。有什么想法可以解决这个问题吗? (我有大约 1e5 条记录..)
  • 10k 条记录不多,肯定是其他原因导致溢出。你的输入向量有多长?它们中的数字范围是多少?您是否对它们应用了任何预处理步骤(例如以某种方式对其进行标准化)?
  • 数据向量为 24 x 10k。我已经在预处理中对数据进行了标准化,所以它们都是 0 到 1 之间的浮点数。
猜你喜欢
  • 2017-08-06
  • 1970-01-01
  • 1970-01-01
  • 2016-01-03
  • 2015-11-20
  • 2021-09-16
  • 1970-01-01
  • 2017-06-09
  • 2015-06-15
相关资源
最近更新 更多