python - 用于确定 k 均值中的 k 的 k 折交叉验证?

标签 python statistics numpy nlp machine-learning

在文档聚类过程中,作为数据预处理步骤,我首先应用奇异向量分解得到USVt 然后通过选择适当数量的特征值,我截断了 Vt,这让我从阅读的内容中得到了很好的文档-文档相关性 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 的引用/实现/建议。

最佳答案

要运行 k 折交叉验证,您需要一些质量度量来优化。这可以是分类度量,例如准确性或 F1 ,或一个专门的,如 V-measure .

即使是我所知道的聚类质量度量也需要标记的数据集(“ground truth”)才能起作用;与分类的不同之处在于,您只需要标记部分数据即可进行评估,而 k-means 算法可以利用所有数据来确定质心,从而确定聚类。

V 测量和 several other scores在 scikit-learn 中实现,以及通用 cross validation代码和“网格搜索”模块,该模块根据使用 k-fold CV 的指定评估度量进行优化。 免责声明:我参与了 scikit-learn 的开发,尽管我没有编写任何提到的代码。

关于python - 用于确定 k 均值中的 k 的 k 折交叉验证?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6629165/

相关文章:

python - SVD with numpy - 结果解释

python - 单轴索引为字符串的 Numpy 数组(矩阵)

python - Python 的 time.process_time() 是否包含子进程占用的 CPU 时间?如何包含它?

python - conda 构建无法识别 Conda 软件包?

python - 三重奏 : multiple tasks reading from the same fd

python - 使用pymc用MCMC拟合两个正态分布(直方图)?

statistics - 寻找模式和统计分析的最佳语言或程序?

optimization - 数学 : how to find the max of an expression with exponents as parameters

python - 使用 scipysolve_ivp 在时间步之间运行代码

python - 将字符串拆分为列表并将项目转换为 int