naive_bayes 0.0.2

  • Installing
  • Versions
  • new40

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?



var classifier = NaiveBayes();

// teach it positive phrases
  ..learn(['amazing', 'awesome', 'movie', 'Yeah', 'Oh', 'boy'], 'positive')
      ['Sweet', 'this', 'is', 'incredibly', 'amazing', 'perfect', 'great'],
// 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)


Naive-Bayes Classifier for node.js

[pull request] New method: .probabilities()

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  naive_bayes: ^0.0.2

2. Install it

You can install packages from the command line:

with pub:

$ pub get

with Flutter:

$ flutter packages get

Alternatively, your editor might support pub get or flutter packages get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:naive_bayes/naive_bayes.dart';
Version Uploaded Documentation Archive
0.0.2 Jan 5, 2019 Go to the documentation of naive_bayes 0.0.2 Download naive_bayes 0.0.2 archive
0.0.1 Jan 5, 2019 Go to the documentation of naive_bayes 0.0.1 Download naive_bayes 0.0.1 archive
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Jan 15, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.1.0
  • pana: 0.12.10


Detected platforms: Flutter, web, other

No platform restriction found in primary library package:naive_bayes/naive_bayes.dart.

Health issues and suggestions

Document public APIs. (-1 points)

11 out of 11 API elements (library, class, field or method) have no adequate dartdoc content. Good documentation improves code readability and discoverability through search.

Maintenance issues and suggestions

Maintain (-20 points)

Changelog entries help clients to follow the progress in your code.

The description is too short. (-20 points)

Add more detail about the package, what it does and what is its target use case. Try to write at least 60 characters.

Package is pre-v0.1 release. (-10 points)

While there is nothing inherently wrong with versions of 0.0.*, it usually means that the author is still experimenting with the general direction of the API.

Maintain an example.

None of the files in your example/ directory matches a known example patterns. Common file name patterns include: main.dart, example.dart or you could also use naive_bayes.dart. Packages with multiple examples should use example/


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.68.0 <3.0.0