使用mahout進(jìn)行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可以對對象進(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.

利用word2vec對關(guān)鍵詞進(jìn)行聚類

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末入愧,一起剝皮案震驚了整個(gè)濱河市涉兽,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌草冈,老刑警劉巖她奥,帶你破解...
    沈念sama閱讀 218,546評論 6 507
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件瓮增,死亡現(xiàn)場離奇詭異,居然都是意外死亡哩俭,警方通過查閱死者的電腦和手機(jī)钉赁,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,224評論 3 395
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來携茂,“玉大人,你說我怎么就攤上這事诅岩』淇啵” “怎么了?”我有些...
    開封第一講書人閱讀 164,911評論 0 354
  • 文/不壞的土叔 我叫張陵吩谦,是天一觀的道長鸳谜。 經(jīng)常有香客問我,道長式廷,這世上最難降的妖魔是什么咐扭? 我笑而不...
    開封第一講書人閱讀 58,737評論 1 294
  • 正文 為了忘掉前任,我火速辦了婚禮滑废,結(jié)果婚禮上蝗肪,老公的妹妹穿的比我還像新娘。我一直安慰自己蠕趁,他們只是感情好薛闪,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,753評論 6 392
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著俺陋,像睡著了一般豁延。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上腊状,一...
    開封第一講書人閱讀 51,598評論 1 305
  • 那天诱咏,我揣著相機(jī)與錄音,去河邊找鬼缴挖。 笑死袋狞,一個(gè)胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的映屋。 我是一名探鬼主播硕并,決...
    沈念sama閱讀 40,338評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼秧荆!你這毒婦竟也來了倔毙?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 39,249評論 0 276
  • 序言:老撾萬榮一對情侶失蹤乙濒,失蹤者是張志新(化名)和其女友劉穎陕赃,沒想到半個(gè)月后卵蛉,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,696評論 1 314
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡么库,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,888評論 3 336
  • 正文 我和宋清朗相戀三年傻丝,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片诉儒。...
    茶點(diǎn)故事閱讀 40,013評論 1 348
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡葡缰,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出忱反,到底是詐尸還是另有隱情泛释,我是刑警寧澤,帶...
    沈念sama閱讀 35,731評論 5 346
  • 正文 年R本政府宣布温算,位于F島的核電站怜校,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏注竿。R本人自食惡果不足惜茄茁,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,348評論 3 330
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望巩割。 院中可真熱鬧裙顽,春花似錦、人聲如沸宣谈。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,929評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽蒲祈。三九已至甘萧,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間梆掸,已是汗流浹背扬卷。 一陣腳步聲響...
    開封第一講書人閱讀 33,048評論 1 270
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留酸钦,地道東北人怪得。 一個(gè)月前我還...
    沈念sama閱讀 48,203評論 3 370
  • 正文 我出身青樓,卻偏偏與公主長得像卑硫,于是被迫代替她去往敵國和親徒恋。 傳聞我的和親對象是個(gè)殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,960評論 2 355

推薦閱讀更多精彩內(nèi)容