Term Frequency - Inverse Document Frequency in Ruby
Ruby
Switch branches/tags
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib
spec
.document
.gitignore
LICENSE
README.rdoc
Rakefile
VERSION
tf_idf.gemspec

README.rdoc

Tf-Idf

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 © 2009 Red Davis. See LICENSE for details.