Bayes::Classifier
Bayes::Classifier allows you to classify strings with naive Bayes classifier.
Installation
Just add the following line to your Gemfile
:
gem 'bayes_classifier'
Then run 'bundle install'.
Usage
# Create new classifier
classifier = Bayes::Classifier.new
# Train classifier with a string
classifier.train :category1, "lorem ipsum dolor sit amet"
# Train classifier with array of strings
classifier.train_with_array :category2, ["the first string", "the second string", "the third string"]
# Train classifier with textfile
classifier.train_with_file :category3, "data/category3.txt"
# Train classifier with CSV file (first column - string, second column - category)
classifier.train_with_csv "data/training.csv"
# Apply weighting to the top words of category
classifier.apply_weighting :category3, 10
# Remove empty categories
classifier.pop_unused
# Classify string
classifier.classify "the string"
# Reset categories
classifier.flush
# Remove all categories
classifier.flush_all
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