Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Simple Naive Bayes classifier

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 lib add possibilty to untrain the system January 29, 2012
Octocat-spinner-32 spec
Octocat-spinner-32 .document Initial commit to naive_bayes. November 14, 2009
Octocat-spinner-32 .gitignore fix specs January 05, 2010
Octocat-spinner-32 LICENSE
Octocat-spinner-32 README.rdoc
Octocat-spinner-32 Rakefile
Octocat-spinner-32 VERSION Version bump to 0.0.3 March 11, 2010
Octocat-spinner-32 naive_bayes.gemspec
README.rdoc

Naive Bayes Classifier

This is an extremely simple, straight forward Naive Bayes implementation.

Install

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

How To Use

require 'rubygems'
require 'naive_bayes'

a = NaiveBayes.new(:spam, :ham)

a.train(:spam, 'bad', 'word')
a.train(:ham, 'good', 'word')

b = "this is a bad sentence".split(' ')

a.classify(*b)
  #=> [:spam, 0.03125]

You can also tell your classifier to save itself, so its easy for you to pick up where you left off:

require 'rubygems'
require 'naive_bayes'

a = NaiveBayes.new(:spam, :ham)
a.db_filepath = 'path/to/anywhere.nb'

a.train(:spam, 'bad', 'word')
a.train(:ham, 'good', 'word')

a.save

Some time goes past and we want to classify a new document we just received…

require 'rubygems'
require 'naive_bayes'

a = NaiveBayes.load('path/to/file') 

b = "this is a bad sentence".split(' ')

# It's as if we were never apart
a.classify(*b)
  #=> [:spam, 0.03125]

Copyright

Copyright © 2009 Red Davis. See LICENSE for details.

Something went wrong with that request. Please try again.