關於HashVectorizer

寫在前面:HashVectorizer與tfidf類似,都是講文本向量化的表示方法,但它節省內存,也更快。當數據集較大時,可以作爲tfidf的替代。

在這裏插入圖片描述
from:https://www.cnblogs.com/pinard/p/6688348.html

說明2:
在這裏插入圖片描述
來自:https://stackoverflow.com/questions/30024122/what-is-the-difference-between-hashing-vectorizer-and-count-vectorizer-when-eac

使用說明

在使用時,我以from sklearn.feature_extraction.text.HashingVectorizer爲例:
1、默認n_features是1048576.也就是2的20次方。所以如果你原來詞典長度沒有這麼大,你想當與在增加維度。你可以手動修改參數

from sklearn.feature_extraction.text import HashingVectorizer
vectorizer = HashingVectorizer()
print(vectorizer.transform(['a very small document']).shape)
(1, 1048576)

small_vectorizer = HashingVectorizer(n_features=5)
print(small_vectorizer.transform(['a very small document']).shape)    
(1, 5)

來自:
https://datascience.stackexchange.com/questions/22250/what-is-the-difference-between-a-hashing-vectorizer-and-a-tfidf-vectorizer
2.至於hash trick是怎麼個hash法:
在這裏插入圖片描述
同樣來自第一個鏈接。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章