naivebayes

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

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
Repository

naivebayes

Owner
Statistic
  • 1
  • 1
  • 0
  • 0
  • 0
  • over 7 years ago
  • December 1, 2016
License

MIT License

Links
Synced at

Thu, 02 May 2024 22:08:55 GMT

Languages