我想幾千文件進行分類,每個幾行。我之前使用過一些常用的單詞,但這次想使用哈希算法,而且我無法理解實現。有在我周圍的數據8000獨特的話,所以我的數字128 * 128應該足夠如何在python中實現一攬子詞語功能哈希?
我使用的大多是這些來源:
http://blog.someben.com/2013/01/hashing-lang/ http://www.hpl.hp.com/techreports/2008/HPL-2008-91R1.pdf
這裏是我的功能generatve特徵向量每個文檔:
import mmh3
def add_doc(text):
text = str.split(text)
d_input = dict()
for word in text:
hashed_token = mmh3.hash(word) % 127
d_input[hashed_token] = d_input.setdefault(hashed_token, 0) + 1
return(d_input)
現在我必須做一些錯誤的,或者不理解一些地方,因爲那裏似乎是一個巨大的碰撞量。任何幫助,將不勝感激
你想找到127個在文本最常用的詞:['collections.Counter(text.split()).most_common(127)'](http://docs.python.org/2/library/ collections.html#collections.Counter)? – jfs 2013-02-16 23:43:57