NBClass
This gem provides a naive bayes classifier for models with N features. Simply put given examples of pre-defined categories the classifier learns how to classify new unknown examples.
Usage
Classifier can be used in three steps:
Provide category names and its respective training set
Train classifier with provided categories
Classify models
For instance the example below shows how to classify words in categories test_a and test_b. Taking in consideration the number of occurrences of each word in both categories besides the frequency of the category the classifier returns the most probable category for the given collection of features.
require 'nb_class/classifier'
# 1 - Providing examples
classifier = NBClass::Classifier.new
classifier.not_spam << "Hi Joe, how are you?"
classifier.spam << "Buy products you don't need"
# 2 - Train classifier
classifier.train
# 3 - Classify new examples
classifier.classify("Hi James, are you going?") # => not_spam
classifier.classify("Buy not needed product") # => spam
Planed Future Features
- Load category examples from external files to reduce code size
- Load pre-trained data from file to decrease classifier initialization time
- Optimize algorithms to use pre-calculated values
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request