Naive bayes classifier library. Implemented by Scala.
This is porting from ptnplanet/Java-Naive-Bayes-Classifier
libraryDependencies ++= Seq(
"com.tsukaby" %% "naive-bayes-classifier-scala" % "0.2.0"
)
This library has been published in the Maven central.
// Create instance
val bayes = new BayesClassifier[String, String]()
// Learning
bayes.learn("technology", "github" :: "git" :: "tech" :: "technology" :: Nil)
bayes.learn("weather", "sun" :: "rain" :: "cloud" :: "weather" :: "snow" :: Nil)
bayes.learn("government", "ballot" :: "winner" :: "party" :: "money" :: "candidate" :: Nil)
val unknownText1 = "I use git".split(" ")
val unknownText2 = "Today's weather is snow".split(" ")
val unknownText3 = "I will vote for that party".split(" ")
// Classify
println(bayes.classify(unknownText1).map(_.category).getOrElse("")) // technology
println(bayes.classify(unknownText2).map(_.category).getOrElse("")) // weather
println(bayes.classify(unknownText3).map(_.category).getOrElse("")) // government
I'm seeking your PR!!! I'm easy.
For example.
- Bug fix
- Refactoring the code.
- Add new features and others.
- Fix my odd English texts.
Copyright 2015 - 2017 tsukaby.com
MIT License