gul

gullible

A naive Bayes classifier in JavaScript

Showing:

Popularity

Downloads/wk

1

GitHub Stars

0

Maintenance

Last Commit

6yrs ago

Contributors

0

Package

Dependencies

0

Size (min+gzip)

0.7KB

License

MIT

Type Definitions

Tree-Shakeable

No?

Categories

Readme

Gullible

A naive Bayes text classifier in JavaScript.

Installation

The easiest way is to use npm:

npm install gullible

Alternatively, you can clone the git repository:

git clone https://github.com/erdiaker/gullible.git

Examples

// Load module
var Gullible = require('gullible');

// Create a new classifier instance
var c = new Gullible();

// Prepare a training set 
var trainSet = [
  {
    text: 'My name is Ozymandias, king of kings: Look on my works, ye Mighty, and despair!', 
    label: 'ozymandias'
  },
  { 
    text: 'A horse! A horse! My kingdom for a horse!',
    label: 'edward_iii'
  }
];

// Learn some text-class pairs
c.learn(trainSet[0].text, trainSet[0].label);
c.learn(trainSet[1].text, trainSet[1].label);

// Classify a new text
var testText = 'Hey! Wanna trade your horse for my kingdom?';
var cls = c.classify(testText);
console.log(cls); // edward_iii

// Estimate a score for text-class pair
var scoreEd = c.estimate(testText, 'edward_iii');
var scoreOzy = c.estimate(testText, 'ozymandias');
console.log(scoreEd > scoreOzy); // true

// Unlearn a previously learned sample.
c.unlearn(trainSet[1].text, trainSet[1].label);
var cls2 = c.classify(testText);
console.log(cls2); // ozymandias

// Serialize classifier as a JSON string
var serialized = Gullible.toJSON(c);

// Restore serialized classifier
var restored = Gullible.fromJSON(serialized);

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100