Project Awesome project awesome

Semantic Analysis > tf_idf

Term Frequency / Inverse Document Frequency in pure Ruby.

Package 35 stars GitHub

= Tf-Idf

http://en.wikipedia.org/wiki/Tf–idf

== Install

gem sources -a http://gemcutter.org sudo gem install tf_idf

== How To Use require 'rubygems' require 'tf_idf'

data = [%w{a a a a a a a a b b}, %w{a a}]

a = TfIdf.new(data)

To find the term frequencies

a.tf #=> [{'b' => 0.2, 'a' => etc...}, {'a' => 1}]

To find the inverse document frequency

a.idf #=> {'b' => 0.301... etc...}

And to find the tf-idf

a.tf_idf #=> [{'b' => 0.0602, 'a' => etc...}, {etc...}]

== Copyright

Copyright (c) 2009 Red Davis. See LICENSE for details.

Back to NLP with Ruby