Simple Bayes
A Simple Bayes (a.k.a. Naive Bayes) implementation in Elixir.
Features
- Naive Bayes algorithm
- no external dependencies
- optional keywords weighting
- [] ignore English stop words
- [] additive smoothing
API
bayes = SimpleBayes.init
|> SimpleBayes.train(:apple, "red sweet")
|> SimpleBayes.train(:apple, "green", weight: 0.5)
|> SimpleBayes.train(:apple, "round", weight: 2)
|> SimpleBayes.train(:banana, "sweet")
|> SimpleBayes.train(:banana, "green", weight: 0.5)
|> SimpleBayes.train(:banana, "yellow long", weight: 2)
|> SimpleBayes.train(:orange, "red")
|> SimpleBayes.train(:orange, "yellow sweet", weight: 0.5)
|> SimpleBayes.train(:orange, "round", weight: 2)
bayes |> SimpleBayes.classify_one("Maybe green maybe red but definitely round and sweet.")
# => :apple
bayes |> SimpleBayes.classify("Maybe green maybe red but definitely round and sweet.")
# => %{
# apple: -10.492915521902894,
# orange: -12.544068044350276,
# banana: -14.706795341847975
# }
License
Licensed under MIT