TFIDF calculating confusion

后端 未结 2 477
佛祖请我去吃肉
佛祖请我去吃肉 2021-02-04 15:47

I found the following code on the internet for calculating TFIDF:

https://github.com/timtrueman/tf-idf/blob/master/tf-idf.py

I added \"1+\" in

相关标签:
2条回答
  • 2021-02-04 16:07

    If the word in question is contained in every document in the collection your 1+ change will result in a negative value. As 0 < (x / (1 + x)) < 1 holds for all x > 0. Which results in a negative logarithm.

    In my opinion the correct IDF for a nonexistent word is infinite or undefined, but by adding 1+ to the denominator and the nominator a nonexistent word will have an IDF slightly higher than any existing word and words that exist in every document will have an IDF of zero. Both cases will probably work well with your code.

    0 讨论(0)
  • 2021-02-04 16:19
    1. No. Tf-idf is tf, a non-negative value, times idf, a non-negative value, so it can never be negative. This code seems to be implementing the erroneous definition of tf-idf that's been on the Wikipedia for years (it's been fixed in the meantime).
    0 讨论(0)
提交回复
热议问题