使用mahout进行k-means聚类[翻译]

http://mahout.apache.org/users/clustering/k-means-clustering.html


k-Means is a simple but well-known algorithm for grouping objects, clustering. All objects need to be represented as a set of numerical features. In addition, the user has to specify the number of groups (referred to as k) she wishes to identify.

k-Means可以对对象进行分组,这些对象需要被表示为特征值,并且制定要分为几组。

Each object can be thought of as being represented by some feature vector in an n dimensional space, n being the number of all features used to describe the objects to cluster. The algorithm then randomly chooses k points in that vector space, these point serve as the initial centers of the clusters. Afterwards all objects are each assigned to the center they are closest to. Usually the distance measure is chosen by the user and determined by the learning task.

聚类的思想:while (n<k) { 选择中心点 ——> 计算距离 }

After that, for each cluster a new center is computed by averaging the feature vectors of all objects assigned to it. The process of assigning objects and recomputing centers is repeated until the process converges. The algorithm can be proven to converge after a finite number of iterations.

Several tweaks concerning distance measure, initial center choice and computation of new average centers have been explored, as well as the estimation of the number of clusters k. Yet the main principle always remains the same.


Here is a short shell script outline that will get you started quickly with k-means. This does the following:

简短的运行k-means 的shell脚本大纲

  • Accepts clustering type: kmeans, fuzzykmeans, lda, or streamingkmeans
  • Gets the Reuters dataset
  • Runs org.apache.lucene.benchmark.utils.ExtractReuters to generate reuters-out from reuters-sgm (the downloaded archive)
  • Runs seqdirectory to convert reuters-out to SequenceFile format
  • Runs seq2sparse to convert SequenceFiles to sparse vector format
  • Runs k-means with 20 clusters
  • Runs clusterdump to show results
  • 接受聚类类型:
    1: kmeans, 2: fuzzykmeans, 3:lda, 4:streamingkmeans
  • 获取Reuters的数据集
  • 运行 org.apache.lucene.benchmark.utils.ExtractReuters 生成输出文件,直接运行脚本
  • 转换成二进制文件
  • 转换二进制文件为稀疏向量格式
  • 聚20个分类
  • 显示结果

路透社dataset下载地址:http://www.daviddlewis.com/resources/testcollections/reuters21578/

After following through the output that scrolls past, reading the code will offer you a better understanding.

利用word2vec对关键词进行聚类

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容