最近幾天上火了,居然牙牀破了,小夥伴們要注意身體。想起了陳楚生的《癮》,此刻這歌詞真襯我的情況。愛上了macbook,一點兒都不想碰工作的thinkpad x1,那個屏幕清晰度實在不想忍受,也是用慣了mac的鍵盤,不想再拖個大滑鼠,雖然寫word文檔用觸控板還是不是很習慣。本想著能有點兒時間的時候,重溫一下proteus,但是一直借著沒有好的windows本,所以還是拖著了,每天寫寫nlp的基礎技術成為了習慣,一時半會兒也不想改,這就是溫水裡的青蛙吧,讓我趁著水還沒熱,好好享受一下吧。很想自己也能有一處背靠青山面朝湖水的小憩的地方,一張小咖啡桌,一杯咖啡,一個筆記本,一支筆,一個mac,寫寫文章,微風吹在面上,陽光曬在手上,啊,真是享受呀。

進入今天正題,今天介紹的是Kmeans聚類的示例。語料中已有分好類的新聞文本。代碼中使用了Kmeans和MiniBatch Kmeans兩種方法,只需要改動Kmeans MiniBatchKmeans方法名即可實現兩種聚類演算法。

部分示例代碼運行結果

實例總數 = 3949
1000到1009實例的簇序號: [3 2 3 3 1 2 0 2 2 2]
1000到1009實例的文件名: [data/cluster_data/sci.crypt/10888-15289
data/cluster_data/sci.crypt/11490-15880
data/cluster_data/sci.crypt/11270-15346
data/cluster_data/sci.electronics/12383-53525
data/cluster_data/sci.space/13826-60862
data/cluster_data/sci.electronics/11631-54106
data/cluster_data/sci.space/14235-61437
data/cluster_data/sci.crypt/11508-15928
data/cluster_data/sci.space/13593-60824
data/cluster_data/sci.electronics/12304-52801]
每個簇的前10個顯著特徵:
Cluster 0: she __ ___ baalke ground her kidney my jpl pain
Cluster 1: space henry toronto nasa zoo shuttle hst launch spencer moon
Cluster 2: my any by your do we me will some has
Cluster 3: key clipper chip encryption keys escrow will public phone by

數據位置:

baiziyuandyufei/text_classification?

github.com
圖標

示例代碼位置:

https://github.com/baiziyuandyufei/text_classification/blob/master/Kmeans聚類.py?

github.com


推薦閱讀:

相關文章