Skip to content

torta/naive_bayes.dart

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

naive_bayes: A Naive-Bayes Classifier for Dart [WIP]

naive_bayes takes a document (piece of text), and tells you what category that document belongs to.

from @ttezel's bayes.js and @pwlmaciejewski's pull request.

What can I use this for?

You can use this for categorizing any text content into any arbitrary set of categories. For example:

  • is an email spam, or not spam ?
  • is a news article about technology, politics, or sports ?
  • is a piece of text expressing positive emotions, or negative emotions?

cat

Usage

var classifier = NaiveBayes();

classifier
// teach it positive phrases
  ..learn(
    ['amazing', 'awesome', 'movie', 'Yeah', 'Oh', 'boy'],
    'positive',
  )
  ..learn(
    ['Sweet', 'this', 'is', 'incredibly', 'amazing', 'perfect', 'great'],
    'positive',
  )
// teach it a negative phrase
  ..learn(
    ['terrible', 'shitty', 'thing', 'Damn', 'Sucks'],
    'negative',
  );

// now ask it to categorize a document it has never seen before

classifier.categorize(['awesome', 'cool', 'amazing', 'Yay']);
// => 'positive'

classifier.probabilities(['awesome', 'cool', 'amazing', 'Yay']);
// => [{category: positive, value: -12.218495165528731}, {category: negative, value: -13.462782102101373}]

// serialize the classifier's state as a JSON string.
var stateJson = classifier.toJson()

// load the classifier back from its JSON representation.
var revivedClassifier = NaiveBayes.fromJson(stateJson)

References

Naive-Bayes Classifier for node.js

https://github.com/ttezel/bayes

[pull request] New method: .probabilities()

ttezel/bayes#7

About

A Naive-Bayes Classifier for Dart

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages