naive_bayes 0.0.2

Dart native js
Flutter Android iOS web

A Naive-Bayes Classifier for Dart

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()

https://github.com/ttezel/bayes/pull/7

0
likes
70
pub points
38%
popularity

A Naive-Bayes Classifier for Dart

Repository
View/report issues

Documentation

API reference

Uploader

torta@hloli.net

License

unknown (LICENSE)

More

Packages that depend on naive_bayes