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可以對對象進(jìn)行分組呻澜,這些對象需要被表示為特征值团赁,并且制定要分為幾組牍鞠。
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) { 選擇中心點(diǎn) ——> 計(jì)算距離 }
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:
簡短的運(yùn)行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的數(shù)據(jù)集
- 運(yùn)行
org.apache.lucene.benchmark.utils.ExtractReuters
生成輸出文件茄猫,直接運(yùn)行腳本 - 轉(zhuǎn)換成二進(jìn)制文件
- 轉(zhuǎn)換二進(jìn)制文件為稀疏向量格式
- 聚20個(gè)分類
- 顯示結(jié)果
路透社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.