什么是SKTFIDF矢量器的“idf”?

2024-09-28 22:41:23 发布

您现在位置:Python中文网/ 问答频道 /正文

我认为.idf_inverse document frequency,这意味着它将是

idf_(t) = log( N/ D(t)) with N=Documents in the corpus and D(t)=number of documents which have the term t

这两份文件也是如此

["foo bar bar ist cool und so weiter", "Ich habe hier nichts so gesagt"]

我会为每件事花费一个0.69 = math.log( 2 / 1)的值,为一件事花费一个0 = math.log(2 / 2)的值

但是sklearn似乎使用了不同的方法,因为我得到了1.4061.0

MVCE

from sklearn.feature_extraction.text import TfidfVectorizer
transformer = TfidfVectorizer()
transformer.fit(["foo bar bar ist cool und so weiter", "Ich habe hier nichts so gesagt"])
print(transformer.vocabulary_)
print(transformer.idf_)

这给

{'foo': 2, 'bar': 0, 'ist': 7, 'cool': 1, 'und': 10, 'so': 9, 'weiter': 11, 'ich': 6, 'habe': 4, 'hier': 5, 'nichts': 8, 'gesagt': 3}

[1.40546511 1.40546511 1.40546511 1.40546511 1.40546511 1.40546511
 1.40546511 1.40546511 1.40546511 1.         1.40546511 1.40546511]

Tags: thelogsofoobartransformercoolidf