【发布时间】:2011-10-01 12:45:49
【问题描述】:
在文档聚类过程中,作为数据预处理步骤,我首先应用奇异向量分解得到U、S和Vt,然后通过选择合适数量的特征值截断@987654326 @,现在从我读到的 here 中,这给了我一个很好的文档-文档相关性。现在我正在对矩阵Vt 的列进行聚类,以将相似的文档聚类在一起,为此我选择了 k-means,初始结果看起来对我来说是可以接受的(k = 10 个聚类),但我想更深入地挖掘关于选择 k 值本身。为了确定 k-means 中 k 的簇数,我是 suggested 来查看交叉验证。
在实现它之前,我想弄清楚是否有使用 numpy 或 scipy 的内置方法来实现它。目前,我执行kmeans 的方式是简单地使用scipy 中的函数。
import numpy, scipy
# Preprocess the data and compute svd
U, S, Vt = svd(A) # A is the TFIDF representation of the original term-document matrix
# Obtain the document-document correlations from Vt
# This 50 is the threshold obtained after examining a scree plot of S
docvectors = numpy.transpose(self.Vt[0:50, 0:])
# Prepare the data to run k-means
whitened = whiten(docvectors)
res, idx = kmeans2(whitened, 10, iter=20)
假设我的方法到目前为止是正确的(如果我遗漏了一些步骤,请纠正我),在这个阶段,使用输出执行交叉验证的标准方法是什么?任何关于如何将其应用于 k-means 的参考/实现/建议将不胜感激。
【问题讨论】:
标签: python statistics numpy nlp machine-learning