0.03
No commit activity in last 3 years
No release in over 3 years
Simple straight forward Naive Bayes classifier implementation
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 1.2.9
 Project Readme

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