naive_bayes 0.0.2

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?


Usage #

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)

References #

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 pub get

Alternatively, your editor might support pub get or flutter pub 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';
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 Jul 11, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.15

Health issues and suggestions

Document public APIs. (-1 points)

11 out of 11 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.

Maintenance issues and suggestions

Provide a file named (-20 points)

Changelog entries help developers follow the progress of your package. See the example generated by stagehand.

Package is getting outdated. (-51.23 points)

The package was last published 78 weeks ago.

The package description is too short. (-20 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

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

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

Homepage URL is insecure. (-5 points)

Update the homepage field and use a secure (https) URL.

Update (-2 points)

1 image link is insecure (e.g., use https URLs instead.

Maintain an example.

None of the files in the package's example/ directory matches known example patterns.

Common filename patterns include main.dart, example.dart, and naive_bayes.dart. Packages with multiple examples should provide example/

For more information see the pub package layout conventions.


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