Leg*_*end 5 python statistics nlp numpy machine-learning
在文档聚类处理,作为数据预处理步骤中,我首先施加奇异向量分解,以获得U,S并且Vt然后通过选择本征值I截断的合适数量Vt,这现在给我一个很好的文档的文档相关性从我看这里.现在我在矩阵的列上执行聚类以将Vt类似的文档聚集在一起为此我选择k-means并且初始结果看起来对我来说是可接受的(k = 10个簇)但我想更深入地选择k值本身.为了确定kk-means中的聚类数量,我建议考虑交叉验证.
在实现它之前,我想弄清楚是否有使用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)
Run Code Online (Sandbox Code Playgroud)
假设到目前为止我的方法是正确的(如果我错过了一些步骤,请纠正我),在这个阶段,使用输出执行交叉验证的标准方法是什么?关于如何将其应用于k-means的任何参考/实现/建议将不胜感激.