Не понимаю HashingVectorizer от sklearn - PullRequest
2 голосов
/ 23 мая 2019

Я использую функцию HashingVectorizer из sklearn.feature_extraction.text, но я не понимаю, как она работает.

Мой код

from sklearn.feature_extraction.text import HashingVectorizer
corpus = [ 'This is the first document.',
'This document is the second document.',
'And this is the third one.',
'Is this the first document?']
vectorizer = HashingVectorizer(n_features=2**3)
X = vectorizer.fit_transform(corpus)
print(X)

Мой результат

(0, 0)        -0.8944271909999159
(0, 5)        0.4472135954999579
(0, 6)        0.0
(1, 0)        -0.8164965809277261
(1, 3)        0.4082482904638631
(1, 5)        0.4082482904638631
(1, 6)        0.0
(2, 4)        -0.7071067811865475
(2, 5)        0.7071067811865475
(2, 6)        0.0
(3, 0)        -0.8944271909999159
(3, 5)        0.4472135954999579
(3, 6)        0.0

Я прочитал много статей о Хешировании, как эта статья https://medium.com/value-stream-design/introducing-one-of-the-best-hacks-in-machine-learning-the-hashing-trick-bf6a9c8af18f

Я понимаю эту статью, но не вижу связи с результатом, полученным выше.

Подскажите, пожалуйста, на простом примере, как работает HashingVectorizer, пожалуйста

...