0.0
No commit activity in last 3 years
No release in over 3 years
simply naive bayes implementation in ruby.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Development

~> 1.13
~> 10.0
~> 3.0
 Project Readme

NaiveBayesRb

A very simple Ruby implementation of Naive Bayes classification model. Here is the blog post for it

Design Considerations

  1. the interface closely resembles the python scikit-learn interface.
  2. enable model serialization and persistence, so that the model can be reused and even distributed and shared. With the default MarshalSerializer, it also allows custom serializer to be plugged in.

Usage

basics

nb = NaiveBayesRb::NaiveBayes.new
train = [[1, 20], [2, 21], [3, 22], [4, 23]] 
target = [1, 0, 1, 0] 
test = [[0, 0], [4, 24]]
predictions = nb.fit(train, target).predict(test) #=> [1, 0] 
@nb.accuracy(prediction, [1, 1]) #=> 50

Model Persistence

NaiveBayesRb::NaiveBayes.serializer =       
nb = NaiveBayesRb::NaiveBayes.new
nb.fit(train, target).save('model.pb')

Loading Persisted Model

NaiveBayesRb::NaiveBayes.serializer =       
nb = NaiveBayesRb::NaiveBayes.load('model.pb')

Installation

Add this line to your application's Gemfile:

gem 'naive_bayes_rb'

And then execute:

$ bundle

Or install it yourself as:

$ gem install naive_bayes_rb

Thanks

I followed the tutorials from this blog.