hash trick

https://en.wikipedia.org/wiki/Feature_hashing


 function hashing_vectorizer(features : array of string, N : integer):
     x = new vector[N]
     for f in features:
         h = hash(f)
         x[h % N] += 1
     return x 

如果特征向量是['cat', 'dog', 'cat'];hash函数被定义为:

if f == 'cat':
    hash(f) = 1
elif f == 'dog':
    hash(f) = 2

如果要求输出4维特征,则为[0, 2, 1, 0]

猜你喜欢

转载自blog.csdn.net/zk_j1994/article/details/80811242