写在前面:HashVectorizer与tfidf类似,都是讲文本向量化的表示方法,但它节省内存,也更快。当数据集较大时,可以作为tfidf的替代。
from:https://www.cnblogs.com/pinard/p/6688348.html
使用说明
在使用时,我以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法:
同样来自第一个链接。