naive

Version, currently master branch1 version
  • master branchlatestDec 1, 2016

github.com/ruivieira/naivebayes

A naive Bayes classifier for Crystal based on muatik's naive-bayes-classifier

1 stars
0 dependents
License: MIT

Installation

# Add this to your shard.yml
dependencies:
  naive:
    github: ruivieira/naivebayes
    branch: master

master is a branch, not a release, so this tracks it rather than pinning a version.

Then run:

shards install

shard.yml

Crystal
no constraint declared
License
MIT
Author
Rui Vieira

Dependencies

This version declares no dependencies.

README

naive

Naive Bayes classifier for Crystal (based on muatik's classifier).

Installation

Add this to your application's shard.yml:

dependencies:
  gsl:
    github: ruivieira/naivebayes

Usage

require "naive"

tokeniser = Naive::Tokeniser.new

newsTrainer = Naive::Trainer.new(tokeniser)

newsSet = [
  {"text" => "not to eat too much is not enough to lose weight", "category" => "health"},
  {"text" => "Russia try to invade Ukraine", "category" => "politics"},
  {"text" => "do not neglect exercise", "category" => "health"},
  {"text" => "Syria is the main issue, Obama says", "category" => "politics"},
  {"text" => "eat to lose weight", "category" => "health"},
  {"text" => "you should not eat much", "category" => "health"},
]

newsSet.each { |news|
  newsTrainer.train(news["text"], news["category"])
}

newsClassifier = Naive::Classifier.new(newsTrainer.data, tokeniser)

classification = newsClassifier.classify("Obama is")

puts classification # => {"health" => 1.6666666666666666e-10, "politics" => 0.083333333333333329}

Warning:

  • Not fully test
  • Pre-release (API will break)
  • Not fit for production

Contributing

  1. Fork it ( https://github.com/ruivieira/crystal-gsl/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Contributors

  • ruivieira Rui Vieira - creator, maintainer
  • muatik muatik - original Python code