Method: TFIDF.idf
- Defined in:
- lib/zipf/tfidf.rb
.idf(list_of_hashes) ⇒ Object
returns idf value for each word in a vocabulary
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/zipf/tfidf.rb', line 24 def TFIDF::idf list_of_hashes vocab = list_of_hashes.values.flatten.uniq n = list_of_hashes.size.to_f idf = {} vocab.each { |i| df = list_of_hashes.values.flatten.count i idf[i] = Math.log(n/df) } return idf end |