我认为.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.406
和1.0
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]
目前没有回答
相关问题 更多 >
编程相关推荐